Skip to content

Instantly share code, notes, and snippets.

@cwhy
Created December 23, 2014 03:51
Show Gist options
  • Save cwhy/2e0b85bbd6d7ded77cb2 to your computer and use it in GitHub Desktop.
Save cwhy/2e0b85bbd6d7ded77cb2 to your computer and use it in GitHub Desktop.
SuperDualNumBros
#!/usr/bin/python
# SuperDualNumBros v0.9 by CWhy@guokr
# Python3
from math import ceil, sqrt
Min, Max = 2, 99
def getSameSum(nums):
x, y = nums
the_sum = x + y
slist = []
for i in range(Min, ceil(the_sum/2)):
j = the_sum - i
slist.append((i, j))
return len(slist), slist
def getSameProduct(nums):
x, y = nums
the_prod = x * y
plist = []
for i in range(Min, ceil(sqrt(the_prod))):
j = the_prod/i
if j.is_integer() and j in the_range:
plist.append((i, int(j)))
return len(plist), plist
kudk_list = [] # kudk: I know that you know
for x in range(Min, Max+1):
for y in range(x, Max+1):
Ns, slist = getSameSum((x, y))
if Ns > 1:
plists = map(getSameProduct, slist)
kudk = all(plist[0] >= 2 for plist in plists)
if kudk:
kudk_list.append((x, y))
# print(kudk_list)
iknow_list = [] # Now I know them
kudk_prod = [x * y for (x,y) in kudk_list]
for p in kudk_prod:
if kudk_prod.count(p) == 1:
iknow_list.append(kudk_list[kudk_prod.index(p)])
# print(iknow_list)
iknow2_list = [] # iknow2: I know it, too.
iknow_sum = [x + y for (x,y) in iknow_list]
for s in iknow_sum:
if iknow_sum.count(s) == 1:
iknow2_list.append(iknow_list[iknow_sum.index(s)])
print(iknow2_list)
# >> [(4, 13)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment