Last active
August 25, 2016 08:57
-
-
Save kostasdizas/afe030ba6518fc41e33b1b754b1ab741 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1^2 = 1(1+1)/2 = 1 | |
6^2 = 8(8+1)/2 = 36 | |
35^2 = 49(49+1)/2 = 1225 | |
204^2 = 288(288+1)/2 = 41616 | |
1189^2 = 1681(1681+1)/2 = 1413721 | |
6930^2 = 9800(9800+1)/2 = 48024900 | |
40391^2 = 57121(57121+1)/2 = 1631432881 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import multiprocessing | |
from itertools import combinations_with_replacement | |
def cube_triangle(number1, number2): | |
cube = number1 ** 2 | |
triangle = (number2 * (number2 + 1))/2 | |
if cube == triangle: | |
print "{0}^2 = {1}({1}+1)/2 = {2}".format(number1, number2, cube) | |
sys.stdout.flush() | |
numbers = xrange(1, 10**7) | |
if __name__ == '__main__': | |
for number1, number2 in combinations_with_replacement(numbers, 2): | |
d = multiprocessing.Process(name='cubtri', target=cube_triangle, args=(number1, number2)) | |
d.daemon = True | |
d.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment