Created
December 6, 2011 17:54
-
-
Save jakedobkin/1439174 to your computer and use it in GitHub Desktop.
Euler 38 Python
This file contains hidden or 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
| # first we'll need a set to store results in- that means we won't need to de-dupe | |
| h=set() | |
| total=0; | |
| # obviously i would be less than < 5 digits long, since it's at least n = 2 (number cat number*2) | |
| # and b is less than 7- because with a > 2, that would be 10 digits | |
| for a in range(1,9999): | |
| product = "" | |
| for b in range(1,7): | |
| product += str(a*b) | |
| # now we'll evaluate each string to see if it meets our criteria | |
| # first make sure there are only 9 numbers | |
| if (len(product)==9): | |
| l=[] | |
| total = 0 | |
| for i in range (0,9): | |
| 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(product) | |
| print "max concatable product is",max(h) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment