Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created December 4, 2011 16:14
Show Gist options
  • Select an option

  • Save jakedobkin/1430566 to your computer and use it in GitHub Desktop.

Select an option

Save jakedobkin/1430566 to your computer and use it in GitHub Desktop.
Euler 32
# first we'll need a set to store results in- that means we won't need to de-dupe
h=set()
total=0;
# now, we'lll make the strings-
# 1 digits x 4 digits will be 4 or 5 digits (9-10 total) and 2 digits x 3 digits will by 4 or 5 digits (9-10 total) so try up to 9999x99
for a in range(1,9999):
for b in range(1,99):
product = str(a)+"x"+str(b)+"x"+str(a*b)
# now we'll evaluate each string to see if it meets our criteria
# first make sure there are only 9 numbers (plus two x's =11)
if (len(product)==11):
l=[]
total = 0
for i in range (0,len(product)):
if ((product[i:i+1]) != "x"):
l.append(int(product[i:i+1]))
l.sort()
if (l[0]==1 and l[1]==2 and l[2]==3 and l[3]==4 and l[4]==5 and l[5]==6 and l[6]==7 and l[7]==8 and l[8]==9):
print product
h.add(a*b)
print sum(h)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment