Skip to content

Instantly share code, notes, and snippets.

@arlolra
Created April 10, 2011 23:14
Show Gist options
  • Save arlolra/912830 to your computer and use it in GitHub Desktop.
Save arlolra/912830 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# opzi problem 1
# http://opzi.posterous.com/puzzle-1-youre-invited
divisors = {}
def find_divs(x):
if x not in divisors:
sub_divs= []
max = x/2 + 1
for y in range(1, max):
if x not in sub_divs:
if not x % y:
sub_divs.append(y)
sub_divs + find_divs(y)
divisors[x] = sub_divs
return divisors[x]
def subsets(s, x):
z = sum(s)
if z < x:
return True
elif z == x:
return False
sl = []
for t in s:
nt = list(s)
nt.remove(t)
sl.append(nt)
for r in sl:
if not subsets(r, x):
return False
return True
def main():
for x in range(1, 554):
divs = find_divs(x)
if sum(divs) > x:
if subsets(divs, x):
print x
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment