Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Advertising

Project Euler 1-17
Sunday, June 24th, 2007 at 12:29:18pm MDT 

  1. #!/usr/bin/python
  2. # -*- coding: iso-8859-15 -*-
  3. import math,sys,time,operator
  4.  
  5. # Simple primality check (slow)
  6. # Basic optimization in place: only check up to sqrt(n)
  7. def isprime_basic(n):
  8.         if n == 1: # Special case
  9.                 return False
  10.         for i in xrange(2,int((n**0.5)+1)):
  11.                 if n%i==0:
  12.                         return False
  13.         return True
  14.  
  15. # Build a list of small primes to speed up primality checks
  16. smallprimes=[]
  17. for n in xrange(2,600):
  18.         if isprime_basic(n):
  19.                 smallprimes.append(n)
  20. # Store largest checked prime
  21. lastprime=smallprimes[-1]
  22.  
  23. # Optimize primality checks - checks for small factors first
  24. # Also optimizes out redundant factors (only up to sqrt(n)
  25. # and only if it hasn't been checked before)
  26. def isprime(n):
  27.         if n&1 == 0 and n > 2: #Cheap test for evenness
  28.                 return False
  29.         if n == 1: # Special case
  30.                 return False
  31.         for i in smallprimes: # Check small primes
  32.                 if n > i and n % i == 0: # factor test
  33.                         return False
  34.                 elif n == i: # equal (prime) test
  35.                         return True
  36.                 # Note that n < i Should Never Happen (TM).
  37.         # Bring on The Slowness!
  38.         for i in xrange(lastprime,int((n**0.5)+1),2):
  39.                 if n%i==0:
  40.                         return False
  41.         return True
  42.  
  43. # This is faster than looping over numbers checking with isprime(),
  44. # since it builds a list and uses that as factor checks.
  45. def primesmax(maxn):
  46.         primes = [2] # Start with 2
  47.         for i in xrange(3, maxn, 2): # Run through all ints, skip evens
  48.                 for p in primes: # Check all previous primes
  49.                         if i % p == 0 or p * p > i: # factor test
  50.                                 break
  51.                 if i % p != 0:
  52.                         primes.append(i)
  53.         return primes
  54.  
  55. # Number of primes version
  56. def primesnum(nprimes):
  57.         primes = [2] # Start with 2
  58.         for i in xrange(3, sys.maxint, 2): # Run through all ints, skip evens
  59.                 for p in primes: # Check all previous primes
  60.                         if i % p == 0 or p * p > i: # factor test
  61.                                 break
  62.                 if i % p != 0:
  63.                         primes.append(i)
  64.                         if len(primes) == nprimes:
  65.                                 return primes
  66.         # Yes, python supports longints, but not xrange, and we want to keep this clean
  67.         # Anything needing this many primes would violate the 1-min rule anyway
  68.         # Use a counter and a while loop to prevent this if needed
  69.         print "Cannot calculate %d primes: maximum int reached"%nprimes
  70.         sys.exit(1)
  71.  
  72. # This is basically a looping version of isprime() above
  73. # When it finds a factor, it divides n by it and restarts.
  74. # Note that this starts with low factors, so the factor list
  75. # is sorted.
  76. def factor(n):
  77.         factors=[]
  78.         while True: # Restart checks once we find a factor
  79.                 # Beware those coming from other languages: this is a forelse loop!
  80.                 # Quick reminder: else clause runs when loop completes with no break
  81.                 for i in smallprimes: # Check for small primes as factors
  82.                         if n == i: # n is now prime (and has to be the largest factor)
  83.                                 factors.append(i)
  84.                                 return factors
  85.                         if n % i == 0: # i is a smaller factor of n, divide by it
  86.                                 n = n / i
  87.                                 factors.append(i)
  88.                                 break
  89.                 else:
  90.                         break # Gone through all small primes, time for some larger ones
  91.         while True: # Same deal here, repeat until we find the largest factor
  92.                 for i in xrange(lastprime,int((n**0.5)+1)): # Check all factors smaller than n
  93.                         if n % i == 0: # Factor, divide through
  94.                                 n = n / i
  95.                                 factors.append(i)
  96.                                 break
  97.                 else: # no factors left, n has to be prime (and the largest factor)
  98.                         factors.append(n)
  99.                         return factors
  100.  
  101. # Factor the number, then return all composite factors
  102. def compfactors(n):
  103.         f=factor(n) # Factor the number
  104.         ft=[False]*len(f) # Prepare binary counter
  105.         fl=set([1]) # Make a set of composite factors - this ensures no dupes
  106.         # We're basically implementing a binary counter here
  107.         # ft is an array of "bits" (booleans), which tell us which factors to multiply
  108.         while True:
  109.                 for i in xrange(len(f)): # This is basically counter++
  110.                         if ft[i]:
  111.                                 ft[i] = False
  112.                                 continue
  113.                         else:
  114.                                 ft[i] = True
  115.                                 break
  116.                 else:
  117.                         break
  118.                 p=1 # Now multiply all active factors
  119.                 for i in xrange(len(f)):
  120.                         if ft[i]:
  121.                                 p *= f[i]
  122.                 fl.add(p) # And add this composite factor to the set
  123.         return fl
  124.  
  125.  
  126. # Number to text
  127. def num2words(n):
  128.        
  129.         # Handle 0-99
  130.         def tens_ones(n):
  131.                 w_onesteens = [
  132.                         "zero","one","two","three","four","five","six","seven","eight","nine",
  133.                         "ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"
  134.                 ]
  135.                 w_tens = [
  136.                         None,None,"twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety",
  137.                 ]
  138.                
  139.                 if n > 99:
  140.                         raise ValueError("wtf")
  141.                 if n < 20:
  142.                         return w_onesteens[n]
  143.                 if n%10==0:
  144.                         return w_tens[n/10]
  145.                 return w_tens[n/10]+"-"+w_onesteens[n%10]
  146.        
  147.         # Handle hundreds (0-999)
  148.         def hundreds(n):
  149.                 if n > 999:
  150.                         raise ValueError("wtf")
  151.                 if n < 100:
  152.                         return tens_ones(n)
  153.                 if n%100 == 0:
  154.                         return tens_ones(n/100)+" hundred"
  155.                 return tens_ones(n/100)+" hundred and "+tens_ones(n%100)
  156.        
  157.         # Handle thousands (0-999999)
  158.         def thousands(n):
  159.                 if n > 999999:
  160.                         raise ValueError("wtf")
  161.                 if n < 1000:
  162.                         return hundreds(n)
  163.                 if n%1000==0:
  164.                         return hundreds(n/1000)+" thousand"
  165.                 return hundreds(n/1000)+" thousand "+hundreds(n%1000)
  166.        
  167.         return thousands(n)
  168.  
  169. def stopwatch(f):
  170.         start=time.clock()
  171.         print "======================================================="
  172.         print "Starting problem %s"%f.__name__
  173.         f()
  174.         stop=time.clock()
  175.         print "Problem %s complete in %.3f seconds"%(f.__name__,stop-start)
  176.  
  177. # ============================== problems ==============================
  178.  
  179. # Not much to see here. This is easy.
  180. def sum35():
  181.         sum=0
  182.         for i in xrange(1000):
  183.                 if i % 3 == 0 or 1 % 5 == 0:
  184.                         sum += i
  185.         print sum
  186.  
  187. # Again, straightforward. I could do without the storage of the entire
  188. # sequence, but I'm lazy. It's short anyway.
  189. def fibevensum():
  190.         fibo=[1,2]
  191.         while True:
  192.                 n=fibo[-1]+fibo[-2]
  193.                 if n >= 1000000:
  194.                         break
  195.                 fibo.append(n)
  196.         sum=0
  197.         for i in fibo:
  198.                 if i&1==0:
  199.                         sum += i
  200.         print sum
  201.  
  202. # See factor() above
  203. def largefactor():
  204.         print factor(317584931803)[-1]
  205.  
  206. # Brute force. Relatively slow due to the string conversions, but OK for our purposes here.
  207. def palindrome():
  208.         lg=0
  209.         for i in xrange(100,1000):
  210.                 for j in xrange(100,1000):
  211.                         prod=i*j
  212.                         if prod > lg and str(prod)==str(prod)[-1::-1]:
  213.                                 lg = prod
  214.         print lg
  215.  
  216. # Find factors of 2-20, merge and multiply
  217. def smalldiv():
  218.         fc = {} # fc is a dictionary whey key,value means key**value (factor, number of occurrences)
  219.         for i in xrange(2,20): # Find factors of 2-20
  220.                 fact = factor(i)
  221.                 fc2 = {}
  222.                 for f in fact: # For each factor, accumulate into dictionary fc2
  223.                         cur = fc2.get(f,0)
  224.                         fc2[f] = cur + 1
  225.                 for k,v in fc2.items(): # Then take max(fc_n,fc2_n) for each key in fc,fc2 and set
  226.                         cur = fc.get(k,0)
  227.                         fc[k] = max(cur,v)
  228.         prod = 1
  229.         for k,v in fc.items(): # multiply together all factors (value is the number of times, that is, the exponent)
  230.                 prod *= k**v
  231.         print prod
  232.  
  233. # Nothing of interest here. Just do it and calculate.
  234. def sumsqsqsum():
  235.         msum = sum(range(1,101))
  236.         msumsq = sum(map(lambda x: x**2,range(1,101)))
  237.         print msum**2 - msumsq
  238.  
  239. # See primesnum() above.
  240. def prime10001():
  241.         print primesnum(10001)[-1]
  242.  
  243. # This is an easy algorithm
  244. # Just run through all sequences of 5 digits and find the largest one
  245. def prod5():
  246.         # There is absolutely zero reason to use an int here - we're
  247.         # basically treating this as a string in this sort of problem
  248.         nt="7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450"
  249.        
  250.         gt=0
  251.        
  252.         for s in xrange(len(nt)-4): # go through all start points (note that the last one needs the last 5 digits, hence -4)
  253.                 prod=1
  254.                 for n in xrange(s,s+5): # run through 5 consecutive digits
  255.                         prod *= int(nt[n]) # multiply them together
  256.                 gt = max(prod,gt) # find largest
  257.         print gt
  258.  
  259. # Brute force here, with some obvious stuff:
  260. # - no need to calculate a, since it's always 1000-b-c
  261. # - b < 1000-c always, so keep that in mind and don't waste time
  262. # - b < c always too
  263. def pythtrip():
  264.         for c in xrange(2,1000):
  265.                 bmax=min(c,1000-c)
  266.                 for b in xrange(1,bmax):
  267.                         a=1000-b-c
  268.                         if a < b and a*a+b*b==c*c:
  269.                                 print a*b*c
  270.                                 return
  271.                                
  272.  
  273. # Nothing interesting here - see primesmax above.
  274. def megaprimes():
  275.         print sum(primesmax(1000000))
  276.  
  277. # Just run through everything.
  278. # Of course, left = right and up = down and there are only two diagonals, since
  279. # multiplication is commutative. 4 runs total.
  280. def gridproduct():
  281.         grid = [
  282.                         [ 8, 2,22,97,38,15, 0,40, 0,75, 4, 5, 7,78,52,12,50,77,91, 8],
  283.                         [49,49,99,40,17,81,18,57,60,87,17,40,98,43,69,48, 4,56,62, 0],
  284.                         [81,49,31,73,55,79,14,29,93,71,40,67,53,88,30, 3,49,13,36,65],
  285.                         [52,70,95,23, 4,60,11,42,69,24,68,56, 1,32,56,71,37, 2,36,91],
  286.                         [22,31,16,71,51,67,63,89,41,92,36,54,22,40,40,28,66,33,13,80],
  287.                         [24,47,32,60,99, 3,45, 2,44,75,33,53,78,36,84,20,35,17,12,50],
  288.                         [32,98,81,28,64,23,67,10,26,38,40,67,59,54,70,66,18,38,64,70],
  289.                         [67,26,20,68, 2,62,12,20,95,63,94,39,63, 8,40,91,66,49,94,21],
  290.                         [24,55,58, 5,66,73,99,26,97,17,78,78,96,83,14,88,34,89,63,72],
  291.                         [21,36,23, 9,75, 0,76,44,20,45,35,14, 0,61,33,97,34,31,33,95],
  292.                         [78,17,53,28,22,75,31,67,15,94, 3,80, 4,62,16,14, 9,53,56,92],
  293.                         [16,39, 5,42,96,35,31,47,55,58,88,24, 0,17,54,24,36,29,85,57],
  294.                         [86,56, 0,48,35,71,89, 7, 5,44,44,37,44,60,21,58,51,54,17,58],
  295.                         [19,80,81,68, 5,94,47,69,28,73,92,13,86,52,17,77, 4,89,55,40],
  296.                         [04,52, 8,83,97,35,99,16, 7,97,57,32,16,26,26,79,33,27,98,66],
  297.                         [88,36,68,87,57,62,20,72, 3,46,33,67,46,55,12,32,63,93,53,69],
  298.                         [ 4,42,16,73,38,25,39,11,24,94,72,18, 8,46,29,32,40,62,76,36],
  299.                         [20,69,36,41,72,30,23,88,34,62,99,69,82,67,59,85,74, 4,36,16],
  300.                         [20,73,35,29,78,31,90, 1,74,31,49,71,48,86,81,16,23,57, 5,54],
  301.                         [ 1,70,54,71,83,51,54,69,16,92,33,48,61,43,52, 1,89,19,67,48],
  302.                 ]
  303.         gp=0
  304.         # Rows
  305.         for row in grid: #loop through rows
  306.                 for start in xrange(len(row)-3): #Loop through start items in row
  307.                         p=reduce(operator.mul,row[start:start+4]) # calculate product
  308.                         gp=max(gp,p)
  309.        
  310.         # Columns - just transpose the grid and do the same
  311.         for col in zip(*grid): #loop through columns
  312.                 for start in xrange(len(col)-3): #Loop through start items in column
  313.                         p=reduce(operator.mul,col[start:start+4]) # calculate product
  314.                         gp=max(gp,p)
  315.        
  316.         # Slope=-1 diagonals
  317.         for y in xrange(len(grid)-3): #Loop through start y coordinates
  318.                 for x in xrange(len(grid[y])-3): #Loop through start x coordinates
  319.                         p=grid[y][x] * grid[y+1][x+1] * grid[y+2][x+2] * grid[y+3][x+3] # calculate product
  320.                         gp=max(gp,p)
  321.        
  322.         # Slope=1 diagonals
  323.         for y in xrange(len(grid)-3): #Loop through start y coordinates
  324.                 for x in xrange(len(grid[y])-3): #Loop through start x coordinates
  325.                         p=grid[y+3][x] * grid[y+2][x+1] * grid[y+1][x+2] * grid[y][x+3] # calculate product
  326.                         gp=max(gp,p)
  327.        
  328.         print gp
  329.  
  330. # There's probably a better way of doing this.
  331. # For now, just test all triangle numbers and count factors
  332. def trianglenums():
  333.         # The formula for triangle numbers is:
  334.         # tn(n) = n(n+1)/2
  335.         n=1
  336.         while True:
  337.                 tn=n*(n+1)/2
  338.                 f=compfactors(tn)
  339.                 if len(f) > 500:
  340.                         print tn
  341.                         return
  342.                 n += 1
  343.  
  344. # Python handles large numbers easily, so this is trivial
  345. def sumdigs():
  346.         nums= [
  347.                 37107287533902102798797998220837590246510135740250,
  348.                 46376937677490009712648124896970078050417018260538,
  349.                 74324986199524741059474233309513058123726617309629,
  350.                 91942213363574161572522430563301811072406154908250,
  351.                 23067588207539346171171980310421047513778063246676,
  352.                 89261670696623633820136378418383684178734361726757,
  353.                 28112879812849979408065481931592621691275889832738,
  354.                 44274228917432520321923589422876796487670272189318,
  355.                 47451445736001306439091167216856844588711603153276,
  356.                 70386486105843025439939619828917593665686757934951,
  357.                 62176457141856560629502157223196586755079324193331,
  358.                 64906352462741904929101432445813822663347944758178,
  359.                 92575867718337217661963751590579239728245598838407,
  360.                 58203565325359399008402633568948830189458628227828,
  361.                 80181199384826282014278194139940567587151170094390,
  362.                 35398664372827112653829987240784473053190104293586,
  363.                 86515506006295864861532075273371959191420517255829,
  364.                 71693888707715466499115593487603532921714970056938,
  365.                 54370070576826684624621495650076471787294438377604,
  366.                 53282654108756828443191190634694037855217779295145,
  367.                 36123272525000296071075082563815656710885258350721,
  368.                 45876576172410976447339110607218265236877223636045,
  369.                 17423706905851860660448207621209813287860733969412,
  370.                 81142660418086830619328460811191061556940512689692,
  371.                 51934325451728388641918047049293215058642563049483,
  372.                 62467221648435076201727918039944693004732956340691,
  373.                 15732444386908125794514089057706229429197107928209,
  374.                 55037687525678773091862540744969844508330393682126,
  375.                 18336384825330154686196124348767681297534375946515,
  376.                 80386287592878490201521685554828717201219257766954,
  377.                 78182833757993103614740356856449095527097864797581,
  378.                 16726320100436897842553539920931837441497806860984,
  379.                 48403098129077791799088218795327364475675590848030,
  380.                 87086987551392711854517078544161852424320693150332,
  381.                 59959406895756536782107074926966537676326235447210,
  382.                 69793950679652694742597709739166693763042633987085,
  383.                 41052684708299085211399427365734116182760315001271,
  384.                 65378607361501080857009149939512557028198746004375,
  385.                 35829035317434717326932123578154982629742552737307,
  386.                 94953759765105305946966067683156574377167401875275,
  387.                 88902802571733229619176668713819931811048770190271,
  388.                 25267680276078003013678680992525463401061632866526,
  389.                 36270218540497705585629946580636237993140746255962,
  390.                 24074486908231174977792365466257246923322810917141,
  391.                 91430288197103288597806669760892938638285025333403,
  392.                 34413065578016127815921815005561868836468420090470,
  393.                 23053081172816430487623791969842487255036638784583,
  394.                 11487696932154902810424020138335124462181441773470,
  395.                 63783299490636259666498587618221225225512486764533,
  396.                 67720186971698544312419572409913959008952310058822,
  397.                 95548255300263520781532296796249481641953868218774,
  398.                 76085327132285723110424803456124867697064507995236,
  399.                 37774242535411291684276865538926205024910326572967,
  400.                 23701913275725675285653248258265463092207058596522,
  401.                 29798860272258331913126375147341994889534765745501,
  402.                 18495701454879288984856827726077713721403798879715,
  403.                 38298203783031473527721580348144513491373226651381,
  404.                 34829543829199918180278916522431027392251122869539,
  405.                 40957953066405232632538044100059654939159879593635,
  406.                 29746152185502371307642255121183693803580388584903,
  407.                 41698116222072977186158236678424689157993532961922,
  408.                 62467957194401269043877107275048102390895523597457,
  409.                 23189706772547915061505504953922979530901129967519,
  410.                 86188088225875314529584099251203829009407770775672,
  411.                 11306739708304724483816533873502340845647058077308,
  412.                 82959174767140363198008187129011875491310547126581,
  413.                 97623331044818386269515456334926366572897563400500,
  414.                 42846280183517070527831839425882145521227251250327,
  415.                 55121603546981200581762165212827652751691296897789,
  416.                 32238195734329339946437501907836945765883352399886,
  417.                 75506164965184775180738168837861091527357929701337,
  418.                 62177842752192623401942399639168044983993173312731,
  419.                 32924185707147349566916674687634660915035914677504,
  420.                 99518671430235219628894890102423325116913619626622,
  421.                 73267460800591547471830798392868535206946944540724,
  422.                 76841822524674417161514036427982273348055556214818,
  423.                 97142617910342598647204516893989422179826088076852,
  424.                 87783646182799346313767754307809363333018982642090,
  425.                 10848802521674670883215120185883543223812876952786,
  426.                 71329612474782464538636993009049310363619763878039,
  427.                 62184073572399794223406235393808339651327408011116,
  428.                 66627891981488087797941876876144230030984490851411,
  429.                 60661826293682836764744779239180335110989069790714,
  430.                 85786944089552990653640447425576083659976645795096,
  431.                 66024396409905389607120198219976047599490197230297,
  432.                 64913982680032973156037120041377903785566085089252,
  433.                 16730939319872750275468906903707539413042652315011,
  434.                 94809377245048795150954100921645863754710598436791,
  435.                 78639167021187492431995700641917969777599028300699,
  436.                 15368713711936614952811305876380278410754449733078,
  437.                 40789923115535562561142322423255033685442488917353,
  438.                 44889911501440648020369068063960672322193204149535,
  439.                 41503128880339536053299340368006977710650566631954,
  440.                 81234880673210146739058568557934581403627822703280,
  441.                 82616570773948327592232845941706525094512325230608,
  442.                 22918802058777319719839450180888072429661980811197,
  443.                 77158542502016545090413245809786882778948721859617,
  444.                 72107838435069186155435662884062257473692284509516,
  445.                 20849603980134001723930671666823555245252804609722,
  446.                 53503534226472524250874054075591789781264330331690,
  447.         ]
  448.         print str(sum(nums))[:10]
  449.  
  450. # Use a cache to save a lot of time
  451. # This could be optimized further, since we don't save all nums
  452. # in the sequence to the cache, only the first (current)
  453. def longcollatz():
  454.         longest=0
  455.         longnum=0
  456.         cache={}
  457.         for i in xrange(1,1000000):
  458.                 n=i
  459.                 cnt = 1
  460.                 while n != 1:
  461.                         if n in cache:
  462.                                 cnt += cache[n] - 1
  463.                                 break
  464.                         if n&1==0:
  465.                                 n=n/2
  466.                         else:
  467.                                 n=3*n+1
  468.                         cnt += 1
  469.                 cache[i]=cnt
  470.                 if cnt > longest:
  471.                         longest=cnt
  472.                         longnum=i
  473.         print longnum
  474.  
  475.  
  476. # Recursive brute force implementation, with caching - very fast
  477. def routes():
  478.        
  479.         # Stores number of routes from tuple (x,y)
  480.         subcache = {}
  481.        
  482.         # Calculate subroutes for a mx by my grid, starting from position x,y
  483.         def subroutes(mx,my,x,y):
  484.                 if (x,y) in subcache: # Check cache
  485.                         return subcache[(x,y)]
  486.                 if x == mx: # if x = max, there is only one way to go
  487.                         sr=1
  488.                 elif y == my: # same for y
  489.                         sr=1
  490.                 else:
  491.                         # otherwise calculate subroutes advancing in both directions
  492.                         sr=subroutes(mx,my,x+1,y)+subroutes(mx,my,x,y+1)
  493.                 # cache the result
  494.                 subcache[(x,y)]=sr
  495.                 return sr
  496.                
  497.         print subroutes(20,20,0,0)
  498.  
  499. # Yay easy python longints. Nothing to see here.
  500. def sumpow2():
  501.         # One liner! w00t!
  502.         print sum(map(int,str(2**1000)))
  503.  
  504. # For the work, see num2words above
  505. def numletters():
  506.         sum=0
  507.         for i in range(1,1001):
  508.                 n=num2words(i)
  509.                 l = len(n.replace(" ","").replace("-","")) # leave only letters
  510.                 sum += l
  511.         print sum
  512.  
  513. print "======================================================="
  514. print "Starting problems..."
  515.  
  516. start=time.clock()
  517.  
  518. stopwatch(sum35)
  519. stopwatch(fibevensum)
  520. stopwatch(largefactor)
  521. stopwatch(palindrome)
  522. stopwatch(smalldiv)
  523. stopwatch(sumsqsqsum)
  524. stopwatch(prime10001)
  525. stopwatch(prod5)
  526. stopwatch(pythtrip)
  527. stopwatch(megaprimes)
  528. stopwatch(gridproduct)
  529. stopwatch(trianglenums)
  530. stopwatch(sumdigs)
  531. stopwatch(longcollatz)
  532. stopwatch(routes)
  533. stopwatch(sumpow2)
  534. stopwatch(numletters)
  535.  
  536. print "======================================================="
  537. print "All problems complete. Total time %.3f seconds"%(time.clock()-start)
  538. print "======================================================="

Paste Details

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

worth-right
worth-right