Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge commit 'dscleaver/master'; commit 'javallone/master'; commit 'a…

…nshumishra/master'; commit 'graybill/master'; commit 'jonm/master'
  • Loading branch information...
commit bc152c35dd146bfc92b6d828afdeba534ed32906 5 parents 250c39b + 279e596 + 6182fdd + 69bbceb + e3a479a
Mat Schaffer authored
Showing with 2,061 additions and 0 deletions.
  1. +18 −0 1/Anshu_Mishra/one.rb
  2. +7 −0 1/jonm.py
  3. +25 −0 1/lgraybill.rb
  4. +6 −0 1/mbl.js
  5. +2 −0  1/mschaffer.cj
  6. +5 −0 1/problem.txt
  7. +63 −0 10/javallone.py
  8. +18 −0 10/jonm10.py
  9. +17 −0 10/mschaffer.py
  10. +27 −0 10/mschaffer.rb
  11. +5 −0 10/problem.txt
  12. +31 −0 11/javallone.py
  13. +20 −0 11/javallone_data.txt
  14. +51 −0 11/jonm11.py
  15. +36 −0 11/nsillik.py
  16. +20 −0 11/nsillik.txt
  17. +28 −0 11/problem.txt
  18. +38 −0 12/javallone.py
  19. +20 −0 12/problem.txt
  20. +3 −0  13/javallone.py
  21. +100 −0 13/javallone_data.txt
  22. +1 −0  13/mschaffer.rb
  23. +104 −0 13/problem.txt
  24. +26 −0 14/javallone.py
  25. +64 −0 14/lgraybill.rb
  26. +16 −0 14/problem.txt
  27. +19 −0 15/javallone.py
  28. +1 −0  16/euler_16.clj
  29. +3 −0  16/javallone.py
  30. +15 −0 16/lgraybill.rb
  31. +1 −0  16/mschaffer.rb
  32. +5 −0 16/problem.txt
  33. +60 −0 17/javallone.py
  34. +64 −0 17/lgraybill2.rb
  35. +12 −0 17/mschaffer.rb
  36. +8 −0 17/problem.txt
  37. +13 −0 18/javallone.py
  38. +15 −0 18/javallone_data.txt
  39. +19 −0 19/javallone.py
  40. +41 −0 2/Anshu_Mishra/two.rb
  41. +12 −0 2/jonm.py
  42. +38 −0 2/lgraybill.rb
  43. +13 −0 2/mbl.js
  44. +28 −0 2/mschaffer.cj
  45. +7 −0 2/problem.txt
  46. +3 −0  20/javallone.py
  47. +26 −0 3/Anshu_Mishra/three.rb
  48. +28 −0 3/jonm.py
  49. +38 −0 3/lgraybill.rb
  50. +16 −0 3/mbl.js
  51. +27 −0 3/mschaffer.cj
  52. +5 −0 3/problem.txt
  53. +39 −0 4/Anshu_Mishra/four.rb
  54. +18 −0 4/Jeff Avallone/euler4.py
  55. +20 −0 4/jonm.py
  56. +30 −0 4/mbl.js
  57. +20 −0 4/mschaffer.cj
  58. +34 −0 5/Jeff Avallone/euler5-1.py
  59. +16 −0 5/Jeff Avallone/euler5-2.py
  60. +4 −0 5/Jeff Avallone/euler5-3.py
  61. +86 −0 5/amishra.rb
  62. +24 −0 5/jonm.py
  63. +17 −0 5/mbl.js
  64. +11 −0 5/mschaffer.cj
  65. +2 −0  5/mschaffer.rb
  66. +13 −0 5/nsillik/main.py
  67. +5 −0 5/problem.txt
  68. +4 −0 6/Jeff Avallone/euler6.py
  69. +23 −0 6/jonm.ml
  70. +23 −0 6/lgraybill.rb
  71. +12 −0 6/mschaffer.cj
  72. +13 −0 6/problem.txt
  73. +2 −0  7/euler-7-alt.clj
  74. +19 −0 7/euler_7.clj
  75. +14 −0 7/euler_7.rb
  76. +23 −0 7/javallone_sieve.py
  77. +38 −0 7/javallone_simple.py
  78. +15 −0 7/jonm.py
  79. +18 −0 7/mschaffer.cj
  80. +7 −0 7/nsillik.rb
  81. +5 −0 7/problem.txt
  82. +31 −0 8/jonm.py
  83. +38 −0 8/lgraybill.html
  84. +33 −0 8/lgraybill.rb
  85. +17 −0 8/mschaffer.rb
  86. +28 −0 8/nsillik.py
  87. +5 −0 8/problem.txt
  88. +23 −0 9/javallone.py
  89. +12 −0 9/jonm.py
  90. +32 −0 9/mschaffer.rb
  91. +9 −0 9/problem.txt
  92. +5 −0 README
  93. +5 −0 mschaffer/utils.cj
View
18 1/Anshu_Mishra/one.rb
@@ -0,0 +1,18 @@
+#If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.
+#The sum of these multiples is 23.
+#
+#Find the sum of all the multiples of 3 or 5 below 1000.
+#
+#3(1+2+3+....+333)+5(1+2+3+.....+199)-15(1+2+3+...+66)
+#puts 3*333*334/2+5*199*200/2-15*66*67/2
+#
+
+def sum_of_n_consecutive_numbers (n)
+ n*(n+1)/2
+end
+
+def sum_of_multiples_of_m(max,m)
+ m*sum_of_n_consecutive_numbers(max/m)
+end
+
+puts sum_of_multiples_of_m(999,3)+sum_of_multiples_of_m(999,5)-sum_of_multiples_of_m(999,15)
View
7 1/jonm.py
@@ -0,0 +1,7 @@
+#!/usr/bin/python
+
+sum = 0
+for i in xrange(1000):
+ if (i % 3 == 0) or (i % 5 == 0):
+ sum += i
+print sum
View
25 1/lgraybill.rb
@@ -0,0 +1,25 @@
+#!/usr/bin/env ruby
+
+# Project Euler #1
+# Linus Graybill 11/5/2009
+
+# http://projecteuler.net/index.php?section=problems&id=1
+#
+# If we list all the natural numbers below 10 that are multiples of 3 or 5,
+# we get 3, 5, 6 and 9. The sum of these multiples is 23.
+#
+# Find the sum of all the multiples of 3 or 5 below 1000.
+
+def euler_1
+ number = 1
+ sum = 0
+ while number < 1000
+ if (number % 3 == 0 || number % 5 == 0)
+ sum += number
+ end
+ number += 1
+ end
+ p sum
+end
+
+euler_1()
View
6 1/mbl.js
@@ -0,0 +1,6 @@
+var total = 0;
+for(var i=0; i<1000; i++){
+ if((i % 5 == 0) || (i % 3 == 0))
+ total += i
+}
+print(total)
View
2  1/mschaffer.cj
@@ -0,0 +1,2 @@
+(defn div3or5 [n] (or (zero? (rem n 3)) (zero? (rem n 5))))
+(reduce + (filter div3or5 (range 1000)))
View
5 1/problem.txt
@@ -0,0 +1,5 @@
+http://projecteuler.net/index.php?section=problems&id=1
+
+If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
+
+Find the sum of all the multiples of 3 or 5 below 1000.
View
63 10/javallone.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+
+def simple_sieve(n):
+ potentials = [ True for i in range(0, n + 1) ]
+
+ results = []
+ for i in range(2, n + 1):
+ if not potentials[i]: continue
+
+ results.append(i)
+
+ x = i * i
+ while x <= n:
+ potentials[x] = False
+ x += i
+
+ return results
+
+def wheel_factorize(seed, n):
+ limit = reduce(lambda a, b: a * b, seed)
+
+ potentials = [ True for i in range(0, limit + 1) ]
+ for i in seed:
+ x = i
+ while x <= limit:
+ potentials[x] = False
+ x += i
+
+ mods = []
+ for i in range(1, limit + 1):
+ if potentials[i]: mods.append(i)
+ mods = set(mods)
+
+ results = []
+ for i in range(2, n + 1):
+ if i % limit in mods:
+ results.append(i)
+
+ return results
+
+def full_sieve(seed, n):
+ potentials = [ False for i in range(0, n + 1) ]
+ for i in wheel_factorize(seed, n): potentials[i] = True
+
+ results = seed
+ for i in range(2, n + 1):
+ if not potentials[i]: continue
+
+ results.append(i)
+
+ x = i * i
+ while x <= n:
+ potentials[x] = False
+ x += i
+
+ return results
+
+target = 2000000
+print(reduce(
+ lambda a, b: a + b,
+ full_sieve([2, 3, 5, 7, 11, 13], target)
+ #simple_sieve(target)
+))
View
18 10/jonm10.py
@@ -0,0 +1,18 @@
+#!/usr/bin/python
+
+import math
+
+primes = [2]
+sum = 2
+for i in xrange(3,2000000):
+ prime = True
+ for p in primes:
+ if i % p == 0:
+ prime = False
+ break
+ if p > math.sqrt(i):
+ break
+ if prime:
+ sum += i
+ primes.append(i)
+print sum
View
17 10/mschaffer.py
@@ -0,0 +1,17 @@
+n = 2000000
+source = range(2, n + 1)
+primes = []
+i = 0
+max = n - 1
+
+while i < max:
+ prime = source[i]
+ if prime:
+ primes.append(prime)
+ j = i
+ while j < max:
+ source[j] = False
+ j += prime
+ i += 1
+
+print sum(primes)
View
27 10/mschaffer.rb
@@ -0,0 +1,27 @@
+n = 2_000_000
+list = (2..n).to_a
+primes = []
+i = 0
+max = n - 1
+
+while i < max
+ prime = list[i]
+ if prime
+ primes << prime
+ j = i
+ while j < max
+ list[j] = nil
+ j += prime
+ end
+ end
+ i += 1
+end
+
+# more straightforward, but gc kills you
+# while !list.empty?
+# prime = list.first
+# primes << prime
+# list = list.select { |n| n % prime != 0 }
+# end
+
+p primes.select{|n|n}.inject &:+
View
5 10/problem.txt
@@ -0,0 +1,5 @@
+http://projecteuler.net/index.php?section=problems&id=10
+
+The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
+
+Find the sum of all the primes below two million.
View
31 11/javallone.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+
+grid = []
+
+# Load the grid
+f = open('javallone_data.txt')
+for i in f:
+ row = [ int(x) for x in i.split(" ") ]
+ row.extend([0, 0, 0, 0])
+ grid.append(row)
+f.close()
+
+height = len(grid)
+width = len(grid[0]) - 4
+
+for i in range(0, 4): grid.append([0] * (width + 4))
+
+# Find the product
+coords = [ (r, c) for r in range(0, height) for c in range(0, width) ]
+mappers = [
+ lambda r, c: grid[r][c] * grid[r][c+1] * grid[r][c+2] * grid[r][c+3], # Horizontal
+ lambda r, c: grid[r][c] * grid[r+1][c] * grid[r+2][c] * grid[r+3][c], # Vertical
+ lambda r, c: grid[r][c] * grid[r+1][c+1] * grid[r+2][c+2] * grid[r+3][c+3], # Diagonal \
+ lambda r, c: grid[r][c] * grid[r-1][c+1] * grid[r-2][c+2] * grid[r-3][c+3] # Diagonal /
+]
+
+print(reduce(max, map(
+ lambda m: reduce(max, map(
+ lambda coordinate: m(*coordinate), coords
+ )), mappers
+)))
View
20 11/javallone_data.txt
@@ -0,0 +1,20 @@
+08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
+49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
+81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65
+52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91
+22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80
+24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50
+32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70
+67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21
+24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72
+21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95
+78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92
+16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57
+86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58
+19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40
+04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66
+88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69
+04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36
+20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16
+20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54
+01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48
View
51 11/jonm11.py
@@ -0,0 +1,51 @@
+#!/usr/bin/python
+
+rawgrid = """08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
+49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
+81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65
+52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91
+22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80
+24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50
+32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70
+67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21
+24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72
+21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95
+78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92
+16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57
+86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58
+19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40
+04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66
+88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69
+04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36
+20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16
+20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54
+01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48"""
+grid = map(lambda rl: map(lambda n: int(n), rl.split(" ")),
+ rawgrid.split("\n"))
+max_prod = 1
+# left-to-right
+for row in xrange(0,20):
+ for col in xrange(0,20-3):
+ prod = (grid[row][col] * grid[row][col+1]
+ * grid[row][col+2] * grid[row][col+3])
+ max_prod = max(max_prod, prod)
+# up-and-down
+for row in xrange(0,20-3):
+ for col in xrange(0,20):
+ prod = (grid[row][col] * grid[row+1][col]
+ * grid[row+2][col] * grid[row+3][col])
+ max_prod = max(max_prod, prod)
+# northwest-to-southeast
+for row in xrange(0,20-3):
+ for col in xrange(0,20-3):
+ prod = (grid[row][col] * grid[row+1][col+1]
+ * grid[row+2][col+2] * grid[row+3][col+3])
+ max_prod = max(max_prod, prod)
+# northeast-to-southwest
+for row in xrange(0+3,20):
+ for col in xrange(0,20-3):
+ prod = (grid[row][col] * grid[row-1][col+1]
+ * grid[row-2][col+2] * grid[row-3][col+3])
+ max_prod = max(max_prod, prod)
+print max_prod
+
View
36 11/nsillik.py
@@ -0,0 +1,36 @@
+#!/opt/local/bin/python2.6
+
+import numpy
+f = open('nsillik.txt')
+
+data = []
+
+for line in f.readlines():
+ data.append([int(x, 10) for x in line.replace("\n", "").split(" ")])
+data = numpy.array(data)
+
+cur_max = 0
+for i in range(data.shape[0]):
+ for j in range(data.shape[1]):
+ try:
+ down = data[i:i+4,j]
+ except IndexError:
+ down = numpy.array([0])
+ try:
+ right = data[i,j:j+4]
+ except IndexError:
+ right = numpy.array([0])
+ try:
+ diag = numpy.array([data[i,j], data[i+1,j+1], data[i+2,j+2], data[i+3,j+3]])
+ except IndexError:
+ diag = numpy.array([0])
+ try:
+ diag2 = numpy.array([data[i,j], data[i+1,j-1], data[i+2,j-2], data[i+3,j-3]])
+ except IndexError:
+ diag = numpy.array([0])
+ this_max = max(down.prod(), right.prod(), diag.prod(), diag2.prod())
+ if this_max > cur_max:
+ print down, right, diag, diag2
+ cur_max = this_max
+
+print cur_max
View
20 11/nsillik.txt
@@ -0,0 +1,20 @@
+08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
+49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
+81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65
+52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91
+22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80
+24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50
+32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70
+67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21
+24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72
+21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95
+78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92
+16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57
+86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58
+19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40
+04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66
+88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69
+04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36
+20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16
+20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54
+01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48
View
28 11/problem.txt
@@ -0,0 +1,28 @@
+http://projecteuler.net/index.php?section=problems&id=11
+
+In the 2020 grid below, four numbers along a diagonal line have been marked in parentheses.
+
+08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
+49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
+81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65
+52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91
+22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80
+24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50
+32 98 81 28 64 23 67 10 (26) 38 40 67 59 54 70 66 18 38 64 70
+67 26 20 68 02 62 12 20 95 (63) 94 39 63 08 40 91 66 49 94 21
+24 55 58 05 66 73 99 26 97 17 (78) 78 96 83 14 88 34 89 63 72
+21 36 23 09 75 00 76 44 20 45 35 (14) 00 61 33 97 34 31 33 95
+78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92
+16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57
+86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58
+19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40
+04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66
+88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69
+04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36
+20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16
+20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54
+01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48
+
+The product of these numbers is 26 63 78 14 = 1788696.
+
+What is the greatest product of four adjacent numbers in any direction (up, down, left, right, or diagonally) in the 20x20 grid?
View
38 12/javallone.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+
+def factorization(n):
+ factor = 2
+
+ if n % factor == 0:
+ power = 1
+
+ while n % factor == 0:
+ n, power = n / factor, power + 1
+ yield power
+
+ factor = 3
+ while n > 1:
+ if n % factor == 0:
+ power = 1
+
+ while n % factor == 0:
+ n, power = n / factor, power + 1
+ yield power
+ factor += 2
+
+def num_factors(n):
+ return reduce(
+ lambda a, b: a * b,
+ factorization(n), 1
+ )
+
+triangle = 1
+v = 0
+
+while True:
+ v += triangle
+ triangle += 1
+
+ if num_factors(v) > 500:
+ print v
+ exit(0)
View
20 12/problem.txt
@@ -0,0 +1,20 @@
+http://projecteuler.net/index.php?section=problems&id=12
+
+The sequence of triangle numbers is generated by adding the natural numbers.
+So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:
+
+1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
+
+Let us list the factors of the first seven triangle numbers:
+
+ 1: 1
+ 3: 1,3
+ 6: 1,2,3,6
+10: 1,2,5,10
+15: 1,3,5,15
+21: 1,3,7,21
+28: 1,2,4,7,14,28
+
+We can see that 28 is the first triangle number to have over five divisors.
+
+What is the value of the first triangle number to have over five hundred divisors?
View
3  13/javallone.py
@@ -0,0 +1,3 @@
+#!/usr/bin/env python
+
+print(str(reduce(lambda a, b: a + b, [ int(i) for i in open('javallone_data.txt').readlines() ]))[0:10])
View
100 13/javallone_data.txt
@@ -0,0 +1,100 @@
+37107287533902102798797998220837590246510135740250
+46376937677490009712648124896970078050417018260538
+74324986199524741059474233309513058123726617309629
+91942213363574161572522430563301811072406154908250
+23067588207539346171171980310421047513778063246676
+89261670696623633820136378418383684178734361726757
+28112879812849979408065481931592621691275889832738
+44274228917432520321923589422876796487670272189318
+47451445736001306439091167216856844588711603153276
+70386486105843025439939619828917593665686757934951
+62176457141856560629502157223196586755079324193331
+64906352462741904929101432445813822663347944758178
+92575867718337217661963751590579239728245598838407
+58203565325359399008402633568948830189458628227828
+80181199384826282014278194139940567587151170094390
+35398664372827112653829987240784473053190104293586
+86515506006295864861532075273371959191420517255829
+71693888707715466499115593487603532921714970056938
+54370070576826684624621495650076471787294438377604
+53282654108756828443191190634694037855217779295145
+36123272525000296071075082563815656710885258350721
+45876576172410976447339110607218265236877223636045
+17423706905851860660448207621209813287860733969412
+81142660418086830619328460811191061556940512689692
+51934325451728388641918047049293215058642563049483
+62467221648435076201727918039944693004732956340691
+15732444386908125794514089057706229429197107928209
+55037687525678773091862540744969844508330393682126
+18336384825330154686196124348767681297534375946515
+80386287592878490201521685554828717201219257766954
+78182833757993103614740356856449095527097864797581
+16726320100436897842553539920931837441497806860984
+48403098129077791799088218795327364475675590848030
+87086987551392711854517078544161852424320693150332
+59959406895756536782107074926966537676326235447210
+69793950679652694742597709739166693763042633987085
+41052684708299085211399427365734116182760315001271
+65378607361501080857009149939512557028198746004375
+35829035317434717326932123578154982629742552737307
+94953759765105305946966067683156574377167401875275
+88902802571733229619176668713819931811048770190271
+25267680276078003013678680992525463401061632866526
+36270218540497705585629946580636237993140746255962
+24074486908231174977792365466257246923322810917141
+91430288197103288597806669760892938638285025333403
+34413065578016127815921815005561868836468420090470
+23053081172816430487623791969842487255036638784583
+11487696932154902810424020138335124462181441773470
+63783299490636259666498587618221225225512486764533
+67720186971698544312419572409913959008952310058822
+95548255300263520781532296796249481641953868218774
+76085327132285723110424803456124867697064507995236
+37774242535411291684276865538926205024910326572967
+23701913275725675285653248258265463092207058596522
+29798860272258331913126375147341994889534765745501
+18495701454879288984856827726077713721403798879715
+38298203783031473527721580348144513491373226651381
+34829543829199918180278916522431027392251122869539
+40957953066405232632538044100059654939159879593635
+29746152185502371307642255121183693803580388584903
+41698116222072977186158236678424689157993532961922
+62467957194401269043877107275048102390895523597457
+23189706772547915061505504953922979530901129967519
+86188088225875314529584099251203829009407770775672
+11306739708304724483816533873502340845647058077308
+82959174767140363198008187129011875491310547126581
+97623331044818386269515456334926366572897563400500
+42846280183517070527831839425882145521227251250327
+55121603546981200581762165212827652751691296897789
+32238195734329339946437501907836945765883352399886
+75506164965184775180738168837861091527357929701337
+62177842752192623401942399639168044983993173312731
+32924185707147349566916674687634660915035914677504
+99518671430235219628894890102423325116913619626622
+73267460800591547471830798392868535206946944540724
+76841822524674417161514036427982273348055556214818
+97142617910342598647204516893989422179826088076852
+87783646182799346313767754307809363333018982642090
+10848802521674670883215120185883543223812876952786
+71329612474782464538636993009049310363619763878039
+62184073572399794223406235393808339651327408011116
+66627891981488087797941876876144230030984490851411
+60661826293682836764744779239180335110989069790714
+85786944089552990653640447425576083659976645795096
+66024396409905389607120198219976047599490197230297
+64913982680032973156037120041377903785566085089252
+16730939319872750275468906903707539413042652315011
+94809377245048795150954100921645863754710598436791
+78639167021187492431995700641917969777599028300699
+15368713711936614952811305876380278410754449733078
+40789923115535562561142322423255033685442488917353
+44889911501440648020369068063960672322193204149535
+41503128880339536053299340368006977710650566631954
+81234880673210146739058568557934581403627822703280
+82616570773948327592232845941706525094512325230608
+22918802058777319719839450180888072429661980811197
+77158542502016545090413245809786882778948721859617
+72107838435069186155435662884062257473692284509516
+20849603980134001723930671666823555245252804609722
+53503534226472524250874054075591789781264330331690
View
1  13/mschaffer.rb
@@ -0,0 +1 @@
+puts File.read('problem.txt').split("\n").select{ |l| l=~/^\d/ }.map(&:to_i).reduce(&:+).to_s[0...10]
View
104 13/problem.txt
@@ -0,0 +1,104 @@
+http://projecteuler.net/index.php?section=problems&id=13
+
+Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.
+
+37107287533902102798797998220837590246510135740250
+46376937677490009712648124896970078050417018260538
+74324986199524741059474233309513058123726617309629
+91942213363574161572522430563301811072406154908250
+23067588207539346171171980310421047513778063246676
+89261670696623633820136378418383684178734361726757
+28112879812849979408065481931592621691275889832738
+44274228917432520321923589422876796487670272189318
+47451445736001306439091167216856844588711603153276
+70386486105843025439939619828917593665686757934951
+62176457141856560629502157223196586755079324193331
+64906352462741904929101432445813822663347944758178
+92575867718337217661963751590579239728245598838407
+58203565325359399008402633568948830189458628227828
+80181199384826282014278194139940567587151170094390
+35398664372827112653829987240784473053190104293586
+86515506006295864861532075273371959191420517255829
+71693888707715466499115593487603532921714970056938
+54370070576826684624621495650076471787294438377604
+53282654108756828443191190634694037855217779295145
+36123272525000296071075082563815656710885258350721
+45876576172410976447339110607218265236877223636045
+17423706905851860660448207621209813287860733969412
+81142660418086830619328460811191061556940512689692
+51934325451728388641918047049293215058642563049483
+62467221648435076201727918039944693004732956340691
+15732444386908125794514089057706229429197107928209
+55037687525678773091862540744969844508330393682126
+18336384825330154686196124348767681297534375946515
+80386287592878490201521685554828717201219257766954
+78182833757993103614740356856449095527097864797581
+16726320100436897842553539920931837441497806860984
+48403098129077791799088218795327364475675590848030
+87086987551392711854517078544161852424320693150332
+59959406895756536782107074926966537676326235447210
+69793950679652694742597709739166693763042633987085
+41052684708299085211399427365734116182760315001271
+65378607361501080857009149939512557028198746004375
+35829035317434717326932123578154982629742552737307
+94953759765105305946966067683156574377167401875275
+88902802571733229619176668713819931811048770190271
+25267680276078003013678680992525463401061632866526
+36270218540497705585629946580636237993140746255962
+24074486908231174977792365466257246923322810917141
+91430288197103288597806669760892938638285025333403
+34413065578016127815921815005561868836468420090470
+23053081172816430487623791969842487255036638784583
+11487696932154902810424020138335124462181441773470
+63783299490636259666498587618221225225512486764533
+67720186971698544312419572409913959008952310058822
+95548255300263520781532296796249481641953868218774
+76085327132285723110424803456124867697064507995236
+37774242535411291684276865538926205024910326572967
+23701913275725675285653248258265463092207058596522
+29798860272258331913126375147341994889534765745501
+18495701454879288984856827726077713721403798879715
+38298203783031473527721580348144513491373226651381
+34829543829199918180278916522431027392251122869539
+40957953066405232632538044100059654939159879593635
+29746152185502371307642255121183693803580388584903
+41698116222072977186158236678424689157993532961922
+62467957194401269043877107275048102390895523597457
+23189706772547915061505504953922979530901129967519
+86188088225875314529584099251203829009407770775672
+11306739708304724483816533873502340845647058077308
+82959174767140363198008187129011875491310547126581
+97623331044818386269515456334926366572897563400500
+42846280183517070527831839425882145521227251250327
+55121603546981200581762165212827652751691296897789
+32238195734329339946437501907836945765883352399886
+75506164965184775180738168837861091527357929701337
+62177842752192623401942399639168044983993173312731
+32924185707147349566916674687634660915035914677504
+99518671430235219628894890102423325116913619626622
+73267460800591547471830798392868535206946944540724
+76841822524674417161514036427982273348055556214818
+97142617910342598647204516893989422179826088076852
+87783646182799346313767754307809363333018982642090
+10848802521674670883215120185883543223812876952786
+71329612474782464538636993009049310363619763878039
+62184073572399794223406235393808339651327408011116
+66627891981488087797941876876144230030984490851411
+60661826293682836764744779239180335110989069790714
+85786944089552990653640447425576083659976645795096
+66024396409905389607120198219976047599490197230297
+64913982680032973156037120041377903785566085089252
+16730939319872750275468906903707539413042652315011
+94809377245048795150954100921645863754710598436791
+78639167021187492431995700641917969777599028300699
+15368713711936614952811305876380278410754449733078
+40789923115535562561142322423255033685442488917353
+44889911501440648020369068063960672322193204149535
+41503128880339536053299340368006977710650566631954
+81234880673210146739058568557934581403627822703280
+82616570773948327592232845941706525094512325230608
+22918802058777319719839450180888072429661980811197
+77158542502016545090413245809786882778948721859617
+72107838435069186155435662884062257473692284509516
+20849603980134001723930671666823555245252804609722
+53503534226472524250874054075591789781264330331690
View
26 14/javallone.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+
+memo = {}
+def sequence(n):
+ def internal(n):
+ if n == 1: return 1
+
+ if n % 2 == 0:
+ next = n / 2
+ else:
+ next = 3 * n + 1
+ return 1 + sequence(next)
+
+ if not memo.has_key(n):
+ memo[n] = internal(n)
+ return memo[n]
+
+longest = 0
+start = 0
+for i in range(1, 1000001):
+ s = sequence(i)
+ if s > longest:
+ longest = s
+ start = i
+
+print start
View
64 14/lgraybill.rb
@@ -0,0 +1,64 @@
+# http://projecteuler.net/index.php?section=problems&id=14
+#
+# The following iterative sequence is defined for the set of positive integers:
+#
+# n -> n/2 (n is even)
+# n -> 3n + 1 (n is odd)
+#
+# Using the rule above and starting with 13, we generate the following sequence:
+#
+# 13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1
+#
+# It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms.
+# Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers
+# finish at 1.
+#
+# Which starting number, under one million, produces the longest chain?
+#
+# NOTE: Once the chain starts the terms are allowed to go above one million.
+
+lengths_of_sequences = Array.new
+
+collect_the_lengths_of_the_sequences = lambda { |starting_number, length|
+ h = Hash.new
+ h["val"] = starting_number
+ h["len"] = length
+ lengths_of_sequences << h
+}
+
+find_the_chain = lambda { |n|
+ s_n = n
+ seq = Array.new
+ while n > 1
+ seq << n
+ if n%2 == 0 then n = n/2
+ else n = 3*n + 1
+ end
+ end
+ seq << 1 # add the final 1
+ collect_the_lengths_of_the_sequences[s_n, seq.length]
+}
+
+start = lambda { |num|
+ while num > 1
+ find_the_chain[num]
+ num = num - 1
+ end
+ tmp_arr = Array.new
+ lengths_of_sequences.each do |item|
+ tmp_arr << item["len"]
+ end
+ tmp_arr.sort!
+
+ last_index = tmp_arr[tmp_arr.length-1] # get last index
+ lengths_of_sequences.each do |item|
+ if item["len"] == last_index
+ p "HOLY SMOKES OUR VALUE IS: " + item["val"].to_s
+ end
+ end
+
+}
+
+start[1000000]
+
+
View
16 14/problem.txt
@@ -0,0 +1,16 @@
+http://projecteuler.net/index.php?section=problems&id=14
+
+The following iterative sequence is defined for the set of positive integers:
+
+n -> n/2 (n is even)
+n -> 3n + 1 (n is odd)
+
+Using the rule above and starting with 13, we generate the following sequence:
+
+13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1
+
+It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1.
+
+Which starting number, under one million, produces the longest chain?
+
+NOTE: Once the chain starts the terms are allowed to go above one million.
View
19 15/javallone.py
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+
+# The number of paths from any point on the grid can is from Pascal's Triangle, just rotate the grid
+
+memo = {}
+def factorial(n):
+ def internal(n):
+ if n == 1: return 1
+ return n * factorial(n-1)
+
+ if not memo.has_key(n):
+ memo[n] = internal(n)
+ return memo[n]
+
+def pascalTriangle(n, k):
+ return factorial(n) / (factorial(k) * factorial(n - k))
+
+gridSize = 20
+print pascalTriangle(2 * gridSize, gridSize)
View
1  16/euler_16.clj
@@ -0,0 +1 @@
+(println (apply + (map #(Integer/parseInt (str %1)) (str (bit-shift-left 2 999)))))
View
3  16/javallone.py
@@ -0,0 +1,3 @@
+#!/usr/bin/env python
+
+print(sum([int(i) for i in str(2**1000)]))
View
15 16/lgraybill.rb
@@ -0,0 +1,15 @@
+# http://projecteuler.net/index.php?section=problems&id=16
+#
+# 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
+#
+# What is the sum of the digits of the number 2^1000?
+
+num = 2**1000
+sum = 0
+single_num = num.to_s.split('') #split the number into single digits
+
+single_num.each do |num|
+ sum = sum + num.to_i # add each digit to the sum
+end
+
+puts sum.to_s
View
1  16/mschaffer.rb
@@ -0,0 +1 @@
+puts (2**1000).to_s.scan(/./).map(&:to_i).reduce(&:+)
View
5 16/problem.txt
@@ -0,0 +1,5 @@
+# http://projecteuler.net/index.php?section=problems&id=16
+
+2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
+
+What is the sum of the digits of the number 2^1000?
View
60 17/javallone.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+
+num_to_string = {
+ 1: 'one',
+ 2: 'two',
+ 3: 'three',
+ 4: 'four',
+ 5: 'five',
+ 6: 'six',
+ 7: 'seven',
+ 8: 'eight',
+ 9: 'nine',
+ 10: 'ten',
+ 11: 'eleven',
+ 12: 'twelve',
+ 13: 'thirteen',
+ 14: 'fourteen',
+ 15: 'fifteen',
+ 18: 'eighteen'
+}
+
+tens_to_string = {
+ 0: '',
+ 1: 'teen',
+ 2: 'twenty',
+ 3: 'thirty',
+ 4: 'forty',
+ 5: 'fifty',
+ 6: 'sixty',
+ 7: 'seventy',
+ 8: 'eighty',
+ 9: 'ninety'
+}
+
+def numberStr(number):
+ if number == 1000: return 'onethousand'
+
+ str = ''
+ hundreds = number / 100
+ number = number % 100
+
+ if num_to_string.has_key(hundreds):
+ str += num_to_string[hundreds] + 'hundred'
+ if number > 0:
+ str += 'and'
+
+ if num_to_string.has_key(number):
+ str += num_to_string[number]
+ else:
+ tens = number / 10
+ number = number % 10
+
+ str += tens_to_string[tens]
+
+ if num_to_string.has_key(number):
+ str += num_to_string[number]
+
+ return str
+
+print(sum([len(numberStr(i)) for i in range(1, 1001)]))
View
64 17/lgraybill2.rb
@@ -0,0 +1,64 @@
+class Euler17
+ attr_accessor :sum, :word
+ def initialize(min, max)
+ @range = (min..max)
+ @sum = 0
+ @range.each do |n|
+ @current_num = n
+ assign_word(@current_num)
+ # p @word # uncomment to see the numbers written out as words
+ add_this_shiz_up
+ end
+ end
+
+ # convert a set of digits to a word (start digit, length of num)
+ def convert(dig, len)
+ dig = ("-" + dig.to_s).to_i
+ @tmp_num = (@current_num.to_s[dig, len]).to_i
+ assign_word(@tmp_num).to_s
+ end
+
+ def add_this_shiz_up
+ eng_len = @word.to_s.length #length of the word
+ @sum += eng_len
+ end
+
+ def assign_word(num)
+ @word = case num
+ # Gotta define some stuff manually
+ when 1 then "one"
+ when 2 then "two"
+ when 3 then "three"
+ when 4 then "four"
+ when 5 then "five"
+ when 6 then "six"
+ when 7 then "seven"
+ when 8 then "eight"
+ when 9 then "nine"
+ when 10 then "ten"
+ when 11 then "eleven"
+ when 12 then "twelve"
+ when 13 then "thirteen"
+ when 15 then "fifteen"
+ when 18 then "eighteen" # manually removing extra 't'
+ when 14, 16, 17, 19 then convert(1, 1) + "teen"
+ # Now you can define stuff programatically
+ when 20..29 then "twenty" + convert(1, 1)
+ when 30..39 then "thirty" + convert(1, 1)
+ when 40..49 then "forty" + convert(1, 1)
+ when 50..59 then "fifty" + convert(1, 1)
+ when 80..89 then "eighty" + convert(1, 1) # manually removing extra 't'
+ when 60..79, 90..99 then convert(2, 1) + "ty" + convert(1, 1)
+ when 100..999
+ if num.to_s[-2,2] == "00" # don't append the "and"
+ convert(3,1) + "hundred"
+ else
+ convert(3, 1) + "hundred" + "and" + convert(2, 2)
+ end
+ when 1000 then "onethousand"
+ end
+ end
+ end
+
+solution = Euler17.new(1, 1000)
+p "Booyah: #{solution.sum}"
View
12 17/mschaffer.rb
@@ -0,0 +1,12 @@
+require 'rubygems'
+require 'linguistics'
+
+Linguistics.use :en
+
+class Fixnum
+ def english_length
+ en.numwords.gsub(/[^a-z]/, '').length
+ end
+end
+
+puts (1..1000).map(&:english_length).reduce(&:+)
View
8 17/problem.txt
@@ -0,0 +1,8 @@
+# http://projecteuler.net/index.php?section=problems&id=17
+
+If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.
+
+If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?
+
+
+NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage.
View
13 18/javallone.py
@@ -0,0 +1,13 @@
+#!/usr/bin/env python
+
+f = open("javallone_data.txt")
+triangle = [ [ int(x) for x in line.split(" ") ] for line in f ]
+f.close()
+
+sum = triangle.pop()
+triangle.reverse()
+
+for row in triangle:
+ sum = [ row[c] + max(sum[c], sum[c + 1]) for c in range(0, len(row)) ]
+
+print(sum[0])
View
15 18/javallone_data.txt
@@ -0,0 +1,15 @@
+75
+95 64
+17 47 82
+18 35 87 10
+20 04 82 47 65
+19 01 23 75 03 34
+88 02 77 73 07 63 67
+99 65 04 28 06 16 70 92
+41 41 26 56 83 40 80 70 33
+41 48 72 33 47 32 37 16 94 29
+53 71 44 65 25 43 91 52 97 51 14
+70 11 33 28 77 73 17 78 39 68 17 57
+91 71 52 38 17 14 91 43 58 50 27 29 48
+63 66 04 68 89 53 67 30 73 16 69 87 40 31
+04 62 98 27 23 09 70 98 73 93 38 53 60 04 23
View
19 19/javallone.py
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+
+# Based on algorithm from http://en.wikipedia.org/wiki/Calculating_the_day_of_the_week
+
+month_table = {
+ False: [1, 4, 4, 7, 2, 5, 7, 3, 6, 1, 4, 6],
+ True: [7, 3, 4, 7, 2, 5, 7, 3, 6, 1, 4, 6]
+}
+
+count = 0
+for year in range(1901, 2001):
+ leap_year = (year % 4 == 0) and (year % 100 != 0 or year % 400 == 0)
+ c = 2 * (3 - (year / 100) % 4)
+ y = int((year % 100) * 1.25)
+ for m in month_table[leap_year]:
+ if (c + y + m) % 7 == 0:
+ count += 1
+
+print(count)
View
41 2/Anshu_Mishra/two.rb
@@ -0,0 +1,41 @@
+#Each new term in the Fibonacci sequence is generated by adding the previous two terms.
+#By starting with 1 and 2, the first 10 terms will be:
+#
+#1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
+#
+#Find the sum of all the even-valued terms in the sequence which do not exceed four million.
+#
+#Obersevations : starting with 2 every 3rd number is even (it must be, as to make an even number
+#one needs to add two odds (or two even unlikely here))
+#So, lets try to decompose the fibonacci series in terms of n-3,n-6,n-9, etc...as it make us do
+#less iteration while adding
+#
+# F(n) = F(n-1)+F(n-2) = F(n-2)+F(n-3)+F(n-2) = F(n-3)+2(F(n-2)) = F(n-3) + 2(F(n-3)+ F(n-4))
+# = 3F(n-3) + 2F(n-4)
+# = 3F(n-3) + F(n-4)+F(n-5)+F(n-6) = 4F(n-3) + F(n-6)
+#
+#
+
+
+def find_sum_of_even_terms(limit)
+ if(limit<2)
+ return 0
+ end
+ if(limit<8)
+ return 2
+ end
+ second_last_even_number = 2
+ last_even_number = 8
+ current_number = 4*last_even_number+second_last_even_number
+ sum=second_last_even_number+last_even_number
+
+ while current_number<=limit
+ sum+=current_number
+ second_last_even_number = last_even_number
+ last_even_number = current_number
+ current_number = 4*last_even_number+second_last_even_number
+ end
+ sum
+end
+
+puts find_sum_of_even_terms(4000000)
View
12 2/jonm.py
@@ -0,0 +1,12 @@
+#!/usr/bin/python
+
+i_2 = 0
+i_1 = 1
+sum = 0
+while True:
+ i = i_1 + i_2
+ if (i % 2 == 0): sum += i
+ i_2 = i_1
+ i_1 = i
+ if i >= 4000000: break
+print sum
View
38 2/lgraybill.rb
@@ -0,0 +1,38 @@
+#!/usr/bin/env ruby
+
+# Project Euler #2
+# Linus Graybill 11/5/2009
+
+# http://projecteuler.net/index.php?section=problems&id=2
+#
+# Each new term in the Fibonacci sequence is generated by adding the previous two terms.
+# By starting with 1 and 2, the first 10 terms will be:
+#
+# 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
+#
+# Find the sum of all the even-valued terms in the sequence which do not exceed four million.
+
+def euler_2()
+ tmp_num = 1
+ prev_num = 1
+ next_num = 2
+ sum_of_nums = 0
+ even_fib_seq = Array.new
+ while tmp_num < 4000000
+ tmp_num = prev_num + next_num
+ if tmp_num <4000000
+ if (tmp_num%2 == 0)
+ even_fib_seq << tmp_num
+ end
+ end
+ prev_num = next_num
+ next_num = tmp_num
+ end
+ even_fib_seq.each do |num|
+ sum_of_nums += num
+ end
+ p sum_of_nums.to_s
+
+end
+
+euler_2()
View
13 2/mbl.js
@@ -0,0 +1,13 @@
+function nextFib(last, secondLast){
+ return last + secondLast;
+}
+
+var last = 2
+var secondLast = 1
+var total = last
+while((next = nextFib(last, secondLast)) < 4000000){
+ if(next % 2 == 0){ total = total + next }
+ secondLast = last
+ last = next
+}
+print(total)
View
28 2/mschaffer.cj
@@ -0,0 +1,28 @@
+; using closure-encapsulated state
+(defn newfibgen []
+ (def n1 1)
+ (def n2 1)
+ (fn [] (do
+ (def next (+ n1 n2))
+ (def n1 n2)
+ (def n2 next)
+ next)))
+
+(defn fibsupto [n]
+ (def fib (newfibgen))
+ (loop [current (fib) collected ()]
+ (if (>= current n)
+ collected
+ (recur (fib) (conj collected current)))))
+
+(reduce + (filter even? (fibsupto 4000000)))
+
+; or using lazy sequences
+(defn euler2 [n]
+ (def fibs (lazy-cat '(0 1) (map + fibs (rest fibs))))
+ (reduce + (filter even? (take-while #(< % n) fibs))))
+
+(euler2 4000000)
+
+; one-liner for good measure
+(def fibs (lazy-cat '(0 1) (map + fibs (rest fibs)))) (reduce + (filter even? (take-while #(< % 4000000) fibs)))
View
7 2/problem.txt
@@ -0,0 +1,7 @@
+http://projecteuler.net/index.php?section=problems&id=2
+
+Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
+
+1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
+
+Find the sum of all the even-valued terms in the sequence which do not exceed four million.
View
3  20/javallone.py
@@ -0,0 +1,3 @@
+#!/usr/bin/env python
+
+print(sum([ int(i) for i in str(reduce(lambda a, b: a * b, range(2, 101))) ]))
View
26 3/Anshu_Mishra/three.rb
@@ -0,0 +1,26 @@
+#The prime factors of 13195 are 5, 7, 13 and 29.
+#
+#What is the largest prime factor of the number 600851475143
+#
+#Start dividing the number by the first prime (i.e. 2). Keep dividing by the current factor
+#till the remainder is zero. So, the number left is n/(current_prime_factor)**m, where m is the no. of times
+#current factor was able to divide the number without remainder. Repeat this process with the next
+#prime factor and the number left as a result of previous division and so on, unless the result of
+#division becomes 1. As the prime factor we are using to divide keeps on increasing, and the loop ends
+#when the number is completely divided (or say n become 1), return the current prime factor. This is our
+#largest prime factor
+
+require 'mathn'
+
+def find_largest_prime(n)
+ primes = Prime.new
+ while n > 1
+ current_prime_factor = primes.next
+ while n % current_prime_factor == 0
+ n /= current_prime_factor
+ end
+ end
+ current_prime_factor
+end
+
+puts find_largest_prime(600851475143)
View
28 3/jonm.py
@@ -0,0 +1,28 @@
+#!/usr/bin/python
+
+import math
+
+def prime(n):
+ if n < 4: return True
+ max = int(math.floor(math.sqrt(float(n))))
+ for i in xrange(max+1):
+ if i < 2: continue
+ if (n % i == 0): return False
+ return True
+
+x = 600851475143
+out = -1
+max = int(math.floor(math.sqrt(x)))
+best = -1
+for i in xrange(1,max+1):
+ if (x % i == 0):
+ other = x / i
+ if (prime(other)):
+ out = other
+ break
+ if (prime(i)):
+ best = i
+if out == -1:
+ print best
+else:
+ print out
View
38 3/lgraybill.rb
@@ -0,0 +1,38 @@
+#!/usr/bin/env ruby
+
+# Project Euler #3
+# Linus Graybill 11/7/2009
+
+# http://projecteuler.net/index.php?section=problems&id=3
+#
+# The prime factors of 13195 are 5, 7, 13 and 29.
+#
+# What is the largest prime factor of the number 600851475143 ?
+
+def largest_prime_factor(number)
+ # start with the number and go backwards
+ while number > 0
+ numb_split = number.to_s.split('')
+ numb_split_length = numb_split.length
+ #p numb_split[numb_split_length - 1]
+ if numb_split[numb_split_length - 1] == "5" || numb_split[numb_split_length - 1] == "0"
+
+
+ elsif number%2 == 0 && number > 2
+ # definitely not prime
+ elsif number%2 == 0 && number%3 == 0
+
+
+ else
+ # test if number is prime
+ # if number is prime
+
+
+ p number.to_s
+ end
+ number -= 1
+ end
+
+end
+
+largest_prime_factor(1000)
View
16 3/mbl.js
@@ -0,0 +1,16 @@
+var num = 600851475143
+var div = 2
+
+// divides out sucessively larger factors until there's nothing left to divide by.
+while(num > 1){
+ // if it's a factor, remove it and try again
+ if(0 == (num % div)){
+ num = num / div
+ // otherwise try the next biggest number
+ }else{
+ div = div + 1
+ }
+}
+
+print(div)
+
View
27 3/mschaffer.cj
@@ -0,0 +1,27 @@
+(require 'clojure.contrib.math)
+
+(defn primes-below [n]
+ (let [limit (sqrt n)]
+ (loop [primes () siv (range 2 (inc n))]
+ (let [prime (first siv)
+ possible-prime (fn [n] (not (zero? (rem n prime))))]
+ (if (> prime limit)
+ (concat primes siv)
+ (recur (concat primes (list prime))
+ (filter possible-prime (rest siv))))))))
+
+(do (primes-below 100000000) nil)
+
+(defn euler3 [n]
+ (loop [remainder n primes (primes-below n)]
+ (let [current (first primes)]
+ (if (= (/ remainder current) 1)
+ current
+ (if (zero? (rem remainder current))
+ (loop ))
+
+(def x 0)
+(while (> x 3) (def x (inc x)) (println x))
+x
+(euler3 13195)
+(euler3 600851475143)
View
5 3/problem.txt
@@ -0,0 +1,5 @@
+http://projecteuler.net/index.php?section=problems&id=3
+
+The prime factors of 13195 are 5, 7, 13 and 29.
+
+What is the largest prime factor of the number 600851475143 ?
View
39 4/Anshu_Mishra/four.rb
@@ -0,0 +1,39 @@
+#
+#A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99.
+#
+#Find the largest palindrome made from the product of two 3-digit numbers
+#
+# Observations :
+# Number = xyzzyx = 100001*x + 100010*y + 1100*z (which is divisible by 11)
+#
+#
+
+
+
+
+def largest_palindrome_for_even_digits(n)
+ max_val = 0
+ multiplier_x = get_multiplier_x(n)
+ n.downto(100) { |y|
+ multiplier_x.each { |x|
+ product = x * y
+ if product.to_s == product.to_s.reverse
+ max_val = [max_val, product].max
+ end
+ }
+ }
+ max_val
+end
+
+
+def get_multiplier_x (n)
+ multipliers = []
+ current_val = n/11*11
+ while current_val > 100
+ multipliers << current_val
+ current_val-=11
+ end
+ multipliers
+end
+
+puts largest_palindrome_for_even_digits(999)
View
18 4/Jeff Avallone/euler4.py
@@ -0,0 +1,18 @@
+#!/usr/bin/env python
+
+digits = [(x, y, z) for x in range(1, 10) for y in range(0, 10) for z in range(0, 10)]
+digits.reverse()
+
+palindromes = []
+palindromes.extend([x * 100001 + y * 10010 + z * 1100 for x, y, z in digits]) # 6-digit palindromes
+palindromes.extend([x * 10001 + y * 1010 + z * 100 for x, y, z in digits]) # 5-digit palindromes
+
+# Find the first palindrome made with the product of 2 3-digit numbers
+for p in palindromes:
+ for i in range(100, 1000):
+ if p % i != 0: continue
+
+ factor = p / i
+ if len(str(factor)) == 3:
+ print(p)
+ exit(0)
View
20 4/jonm.py
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+
+import math
+import sys
+
+def palindrome(n):
+ s = str(n)
+ for i in xrange(int(math.ceil(len(s)/2))):
+ if s[i] != s[len(s)-1-i]: return False
+ return True
+
+best = -1
+for i in xrange(100,1000):
+ for j in xrange(100,1000):
+ n1 = 1099 - i
+ n2 = 1099 - j
+ prod = n1 * n2
+ if palindrome(prod) and prod > best:
+ best = prod
+print best
View
30 4/mbl.js
@@ -0,0 +1,30 @@
+function reverseString(str){
+ return str.split("").reverse().join("")
+}
+
+function isPalindrome(num){
+ return (num+"") == reverseString(num+"")
+}
+
+/* super brute force! */
+palindromes = []
+for(var i = 999 * 999; i >=0; i--){
+ if(isPalindrome(i)){
+ palindromes.push(i)
+ }
+}
+
+for(i = 0; i<palindromes.length; i++){
+ palindrome = palindromes[i]
+ print("trying palindrome: " + palindrome)
+ j = 100
+ for(j = 100; j < 1000; j++){
+ if(palindrome % j != 0){ continue }
+ factor = palindrome / j
+ if((factor+"").length == 3){
+ print(palindrome)
+ break
+ }
+ }
+}
+
View
20 4/mschaffer.cj
@@ -0,0 +1,20 @@
+(defn pow [n e]
+ (loop [n n e e acc 1]
+ (if (zero? e)
+ acc
+ (recur n (dec e) (* n acc)))))
+
+(defn palendrome? [subject]
+ (let [subject (list* (str subject))]
+ (= subject (reverse subject))))
+
+(defn euler4 [n]
+ (let [min (pow 10 (dec n))
+ max (pow 10 n)
+ items (range min max)]
+ (last (sort
+ (for [i items j items]
+ (let [product (* i j)]
+ (if (palendrome? product) product 0)))))))
+
+(println (euler4 3))
View
34 5/Jeff Avallone/euler5-1.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+
+def factors(n):
+ result = {}
+
+ if n % 2 == 0:
+ result[2] = 0
+ while n % 2 == 0:
+ result[2] += 1
+ n /= 2
+
+ factor = 3
+ while n > 1:
+ if n % factor == 0:
+ result[factor] = 0
+ while n % factor == 0:
+ result[factor] += 1
+ n /= factor
+ factor += 2
+
+ return result
+
+factor_table = {}
+for i in range(2, 21):
+ f = factors(i)
+ for k in f.keys():
+ if not factor_table.has_key(k) or factor_table[k] < f[k]:
+ factor_table[k] = f[k]
+
+result = 1
+for k in factor_table.keys():
+ result *= k ** factor_table[k]
+
+print(result)
View
16 5/Jeff Avallone/euler5-2.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+
+def gcd(a, b):
+ if b == 0:
+ return a
+ else:
+ return gcd(b, a % b)
+
+def lcm(a, b):
+ return a * b / gcd(a, b)
+
+result = 1
+for i in range(2, 21):
+ result = lcm(i, result)
+
+print(result)
View
4 5/Jeff Avallone/euler5-3.py
@@ -0,0 +1,4 @@
+#!/usr/bin/env python
+
+gcd = lambda a, b: (b == 0) and a or gcd(b, a % b)
+print(reduce(lambda a, b: a * b / gcd(a, b), range(2, 21)))
View
86 5/amishra.rb
@@ -0,0 +1,86 @@
+#
+# Directly using the ruby library
+# require 'rational'
+# puts (1..20).inject(1) { |result, n| result.lcm n }
+#
+# The other solution (Code below) Steps :
+# 1. Fetch all the primes less than "n" in an array (it would be automatically sorted, which will save our efforts later)
+# 2. For the smallest member "k" of the prime list, find the maxm power "m" such that k**m <=n (For, e.g. 2**4<20)
+# 3. Replace the smallest member from the array with k**m (For e.g. replace 2 with 16, because anything divisible by k**m
+# would be itself be divisible by k**0..m-1)
+# 4. Repeat the steps 2-3, for the next member of the array (starting with the power #m-1). when the power becomes 1, no need
+# to iterate.
+# 5. Multiply the members of the final array.
+#
+# Sample runs :
+# For n = 10
+#
+# All the primes :
+# [2, 3, 5, 7]
+# All the multipliers :
+# [8, 9, 5, 7]
+# 2520
+#
+# For n = 20
+#
+# All the primes :
+# [2, 3, 5, 7, 11, 13, 17, 19]
+# All the multipliers :
+# [16, 9, 5, 7, 11, 13, 17, 19]
+# 232792560
+#
+
+require 'mathn'
+
+def collect_primes(n)
+ primes_list = []
+ primes = Prime.new
+ primes.each { |x| break if x >= n; primes_list<<x; }
+ puts "All the primes :"
+ p primes_list
+ primes_list
+end
+
+def root(arg, base)
+ arg**(1/base)
+end
+
+def get_all_the_multipliers(n)
+ primes_list = collect_primes(n)
+ max_base = get_max_base_for_two(n)
+
+ primes_list.each_with_index do |item, index|
+ primes_list[index]=item**max_base
+ max_base = get_max_base_for_current_number(n,max_base,primes_list[index+1])
+ if max_base <=1 then break
+ end
+ end
+ puts "All the multipliers :"
+ p primes_list
+ primes_list
+end
+
+def get_mulitiplied_value(n)
+ list_of_multipliers = get_all_the_multipliers(n)
+ list_of_multipliers.inject(1){|total, i| total*i}
+end
+
+def get_max_base_for_two(n)
+ i=2
+ while root(n,i) >= 2
+ i = i+1;
+ end
+ return i-1
+end
+
+def get_max_base_for_current_number(n,max_base, current_number)
+ base = max_base - 1
+ while current_number**base > n
+ base = base - 1
+ end
+ return base
+end
+
+
+puts get_mulitiplied_value(20)
+#puts get_mulitiplied_value(10)
View
24 5/jonm.py
@@ -0,0 +1,24 @@
+#!/usr/bin/python
+
+# 1 = 1
+# 2 = 2
+# 3 = 3
+# 4 = 2^2
+# 5 = 5
+# 6 = 2 * 3
+# 7 = 7
+# 8 = 2^3
+# 9 = 3^2
+# 10 = 2 * 5
+# 11 = 11
+# 12 = 2^2 * 3
+# 13 = 13
+# 14 = 2 * 7
+# 15 = 3 * 5
+# 16 = 2^4
+# 17 = 17
+# 18 = 2 * 3^2
+# 19 = 19
+# 20 = 2^2 * 5
+
+print (2*2*2*2 * 3*3 * 5 * 7 * 11 * 13 * 17 * 19)
View
17 5/mbl.js
@@ -0,0 +1,17 @@
+function gcd(a, b){
+ if(b == 0){
+ return a
+ }else{
+ return gcd(b, a % b)
+ }
+}
+
+function lcm (a, b){
+ return (a * b) / gcd(a, b)
+}
+
+curr = 1
+for(i = 2; i < 20; i++){
+ curr = lcm(curr, i)
+}
+print(curr)
View
11 5/mschaffer.cj
@@ -0,0 +1,11 @@
+(defn gcd [a b]
+ (if (zero? b)
+ a
+ (recur b (rem a b))))
+
+(defn lcm [a b]
+ (/ (* a b) (gcd a b)))
+
+(reduce lcm (range 2 200000))
+
+;(reduce(fn[a b](/(* a b)((fn[a b](if(= b 0)a(recur b(rem a b))))a b)))(range 2 21))
View
2  5/mschaffer.rb
@@ -0,0 +1,2 @@
+#!/usr/bin/env ruby -rmathn
+p (2..20).inject &:lcm
View
13 5/nsillik/main.py
@@ -0,0 +1,13 @@
+#!/usr/bin/env python
+import sys
+
+def main(argv):
+ usage()
+
+ sys.exit(0)
+
+def usage():
+ print "%s blah" % (sys.argv[0])
+
+if __name__ == "__main__":
+ main(sys.argv)
View
5 5/problem.txt
@@ -0,0 +1,5 @@
+http://projecteuler.net/index.php?section=problems&id=5
+
+2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
+
+What is the smallest number that is evenly divisible by all of the numbers from 1 to 20?
View
4 6/Jeff Avallone/euler6.py
@@ -0,0 +1,4 @@
+#!/usr/bin/env python
+
+n = 100
+print(n * (n**2 - 1) * (3 * n + 2) / 12)
View
23 6/jonm.ml
@@ -0,0 +1,23 @@
+(* if f(n-1) = x^2 - y
+ where x = 1 + 2 + ... + (n-1)
+ and y = 1^2 + 2^2 + ... + (n-1)^2
+ then f(n) = (x+n)^2 - (y + n^2)
+ = x^2 + 2xn + n^2 - y - n^2
+ = x^2 + 2xn - y = x^2 - y + 2xn
+ = f(n-1) + 2xn
+ = f(n-1) + 2 * n * (n(n-1)/2)
+ = f(n-1) + n * n * (n-1)
+ = f(n-1) + n^3 - n^2 *)
+let rec f n = match n with
+ 1 -> 0
+| n -> (f (n-1)) + n * n * (n-1);;
+
+(* tail recursive version *)
+let f_tail n =
+ let rec help n acc = match n with
+ 1 -> acc
+ | n -> help (n-1) (acc + n * n * (n-1)) in
+ help n 0;;
+
+Printf.printf "%d\n" (f 100);;
+Printf.printf "%d\n" (f_tail 100);;
View
23 6/lgraybill.rb
@@ -0,0 +1,23 @@
+#!/usr/bin/env ruby
+
+# Project Euler #6
+# Linus Graybill 10/27/2009
+
+# Output for n=100:
+# Sum of the squares: 338350
+# Square of the sum: 25502500
+# The difference: 25164150
+
+def solve_euler_6(n)
+ sum_of_squares = 0
+ tmp_square_of_sums = 0
+ (1..n).each { |num| sqrd_num = num ** 2; sum_of_squares += sqrd_num; }
+ (1..n).each { |num| tmp_square_of_sums += num }
+ square_of_sums = tmp_square_of_sums ** 2
+ the_diff = square_of_sums - sum_of_squares
+ puts "The difference: " + the_diff.to_s
+end
+
+#start = Time.now
+solve_euler_6(100)
+#puts "Took: #{Time.now - start} seconds"
View
12 6/mschaffer.cj
@@ -0,0 +1,12 @@
+(load-file "../mschaffer/utils.cj")
+
+(defn sum-of-squares [n]
+ (reduce + (map #(pow % 2) (range 1 (inc n)))))
+
+(defn square-of-sums [n]
+ (pow (reduce + (range 1 (inc n))) 2))
+
+(defn euler6 [n]
+ (- (square-of-sums n) (sum-of-squares n)))
+
+(euler6 100)
View
13 6/problem.txt
@@ -0,0 +1,13 @@
+http://projecteuler.net/index.php?section=problems&id=6
+
+The sum of the squares of the first ten natural numbers is,
+
+1^2 + 2^2 + ... + 10^2 = 385
+
+The square of the sum of the first ten natural numbers is,
+
+(1 + 2 + ... + 10)^2 = 55^2 = 3025
+
+Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 385 = 2640.
+
+Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
View
2  7/euler-7-alt.clj
@@ -0,0 +1,2 @@
+(use 'clojure.contrib.lazy-seqs)
+(println (nth primes 10000))
View
19 7/euler_7.clj
@@ -0,0 +1,19 @@
+(defn sqrt [x]
+ (int (Math/sqrt x)))
+
+(defn get-smallest-prime-factor [n]
+ (loop [n n d 2]
+ (cond (> d (sqrt n)) n
+ (= n d) n
+ (= 0 (rem n d)) d
+ true (recur n (inc d)))))
+
+(def get-nth-prime
+ (lazy-cat '(2 3)
+ (filter
+ #(= % (get-smallest-prime-factor %))
+ (filter
+ #(or (= 1 (rem % 6)) (= 5 (rem % 6)))
+ (take-nth 2 (iterate inc 3))))))
+
+(println (nth get-nth-prime 10000))
View
14 7/euler_7.rb
@@ -0,0 +1,14 @@
+require "mathn"
+infinity = 1.0/0.0
+module Enumerable
+ def lazy_select
+ Enumerator.new do |yielder|
+ each do |obj|
+ yielder.yield(obj) if yield(obj)
+ end
+ end
+ end
+end
+
+p (1..infinity).lazy_select { |v| v.prime? }.take(10001).last
+
View
23 7/javallone_sieve.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+
+def sieve(limit):
+ list = set(range(2, limit+1))
+ primes = []
+
+ while len(list) > 0:
+ p = list.pop()
+ rem = p * p
+ while rem <= limit:
+ list.discard(rem)
+ rem += p
+ primes.append(p)
+
+ return primes
+
+prime_list = []
+limit = 1000000
+while len(prime_list) < 10001:
+ prime_list = sieve(limit)
+ limit *= 10
+
+print(prime_list[10000])
View
38 7/javallone_simple.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+
+from math import sqrt
+
+def memoize(func):
+ memo = {}
+
+ def new_func(*args):
+ if not memo.has_key(args):
+ memo[args] = func(*args)
+ return memo[args]
+
+ return new_func
+
+@memoize
+def isPrime(check):
+ root = sqrt(check)
+ if (root == int(root)):
+ return False
+
+ for i in range(2, int(root) + 1):
+ if not isPrime(i):
+ continue
+
+ if (check % i == 0):
+ return False
+
+ return True
+
+count = 1
+check = 3
+while True:
+ if isPrime(check):
+ count += 1
+ if count == 10001:
+ print(check)
+ break
+ check += 2
View
15 7/jonm.py
@@ -0,0 +1,15 @@
+#!/usr/bin/env python
+
+primes = [2]
+i = 3
+while len(primes) < 10001:
+ prime = True
+ for p in primes:
+ if i % p == 0:
+ prime = False
+ break
+ if prime:
+ primes.append(i)
+ i += 1
+
+print primes[-1]
View
18 7/mschaffer.cj
@@ -0,0 +1,18 @@
+(defn new-prime-generator []
+ (def primes '(2))
+ (defn prime? [n]
+ (loop [divs primes]
+ (cond (empty? divs) true
+ (zero? (rem n (first divs))) false
+ :else (recur (rest divs)))))
+ (defn next-prime []
+ (loop [potential (inc (last primes))]
+ (if (prime? potential)
+ (def primes (concat primes (list potential)))
+ (recur (inc potential))))
+ (last primes))
+ (fn [] (next-prime)))
+
+(def generator (new-prime-generator))
+(dotimes [x (- 10001 2)] (generator))
+(generator)
View
7 7/nsillik.rb
@@ -0,0 +1,7 @@
+#!/usr/bin/env ruby
+# This is embarassing...
+require "mathn"
+
+p = Prime.new()
+10000.times do p.next() end
+print(p.next())
View
5 7/problem.txt
@@ -0,0 +1,5 @@
+http://projecteuler.net/index.php?section=problems&id=7
+
+By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
+
+What is the 10001st prime number?
View
31 8/jonm.py
@@ -0,0 +1,31 @@
+#!/usr/bin/python
+
+rawdigits = """
+73167176531330624919225119674426574742355349194934
+96983520312774506326239578318016984801869478851843
+85861560789112949495459501737958331952853208805511
+12540698747158523863050715693290963295227443043557
+66896648950445244523161731856403098711121722383113
+62229893423380308135336276614282806444486645238749
+30358907296290491560440772390713810515859307960866
+70172427121883998797908792274921901699720888093776
+65727333001053367881220235421809751254540594752243
+52584907711670556013604839586446706324415722155397
+53697817977846174064955149290862569321978468622482
+83972241375657056057490261407972968652414535100474
+82166370484403199890008895243450658541227588666881
+16427171479924442928230863465674813919123162824586
+17866458359124566529476545682848912883142607690042
+24219022671055626321111109370544217506941658960408
+07198403850962455444362981230987879927244284909188
+84580156166097919133875499200524063689912560717606
+05886116467109405077541002256983155200055935729725
+71636269561882670428252483600823257530420752963450
+"""
+concat_digits = rawdigits.replace("\n","")
+max_prod = 1
+for i in xrange(len(concat_digits)-4):
+ seq = concat_digits[i:i+5]
+ prod = int(seq[0]) * int(seq[1]) * int(seq[2]) * int(seq[3]) * int(seq[4])
+ max_prod = max(max_prod, prod)
+print max_prod
View
38 8/lgraybill.html
@@ -0,0 +1,38 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+ "http://www.w3.org/TR/html4/strict.dtd">
+<head>
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
+ <title>euler 8</title>
+
+</head>
+<body id="body" onload="findTheGreatestProduct(bigNumber)">
+ <script type="text/javascript" charset="utf-8">
+
+ // http://projecteuler.net/index.php?section=problems&id=8
+ //
+ // Find the greatest product of five consecutive digits in the 1000-digit number.
+
+ var bigNumber = "7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450";
+
+ function findTheGreatestProduct(number){
+ var products = [];
+ var digits = number.split("");
+ while (digits.length > 5) {
+ var multiples = [];
+ var mult = 1;
+ multiples = digits.slice(0, 5);
+ while (multiples.length !== 0) {
+ mult = mult * multiples[0];
+ multiples.shift();
+ }
+ products.unshift(mult);
+ digits.shift();
+ }
+ var answer = products.sort(function(a,b) { return b-a } );
+ document.write("<h1>Your answer, sir, is " + answer[0] + ".</h1>");
+ }
+
+
+ </script>
+</body>
+</html>
View
33 8/lgraybill.rb
@@ -0,0 +1,33 @@
+#!/usr/bin/env ruby
+
+# Project Euler #8
+# Linus Graybill 11/2/2009
+
+# http://projecteuler.net/index.php?section=problems&id=8
+#
+# Find the greatest product of five consecutive digits in the 1000-digit number.
+#
+# 7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450
+
+big_number = 7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450
+
+def find_greatest_product(number)
+ digits = number.to_s.split('')
+ products = Array.new
+ while digits.length > 5
+ multiples = digits[0..4].to_s.split('')
+ mult = 1
+ while multiples.empty? != true
+ mult = mult * multiples[0] .to_i
+ multiples.shift
+ end
+ products << mult
+ digits.shift
+ end
+ answer = products.sort {|x,y| y <=> x }
+ p "Your answer, sir, is " + answer[0].to_s
+end
+
+# start = Time.now
+find_greatest_product(big_number)
+# puts "Took: #{Time.now - start} seconds"
View
17 8/mschaffer.rb
@@ -0,0 +1,17 @@
+number = File.read(File.join(File.dirname(__FILE__), 'problem.txt')).scan(/^\d+/).join
+
+products = []
+
+0.upto(number.length - 5) do |i|
+ products << number[i..(i+4)].scan(/./).map(&:to_i).inject(&:*)
+end
+
+puts products.max
+
+=begin
+
+a b c d e f g h i j k l m n o p q
+
+[abc(de)] [bc(de)f] [c(de)fg] [(de)fgh] [] [] []
+
+=end
View
28 8/nsillik.py
@@ -0,0 +1,28 @@
+import time
+
+number = 7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450
+numberString = str(number)
+numberList = [int(x) for x in list(numberString)]
+import random
+hugenumber = 1000000
+#hugeNumberList = [random.randint(0,9) for x in range(0, hugenumber)]
+
+def naive(numberList):
+ largest = (-1, -1) # (value, index)
+ for i in range(0, len(numberList)):
+ current = (reduce((lambda x, y: x*y), numberList[i:i+5]), i)
+ if current[0] > largest[0]:
+ largest = current
+ print "Largest product is: %d, at %d" % (largest[0], largest[1])
+
+def profileMethods(funcList, argsList):
+ for func in funcList:
+ t = time.time()
+ func(argsList[0])
+ print("%s %05.2fs" % (func.__name__, time.time() - t))
+
+def main():
+ profileMethods([naive], [numberList])
+
+if __name__ == "__main__":
+ main()
View
5 8/problem.txt
@@ -0,0 +1,5 @@
+http://projecteuler.net/index.php?section=problems&id=8
+
+Find the greatest product of five consecutive digits in the 1000-digit number.
+
+7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450
View
23 9/javallone.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+
+# These implement Euclid's Formula which will generate the triple based on
+# two positive integers m and n.
+# m > n
+fa = lambda m, n: 2 * m * n
+fb = lambda m, n: m * m - n * n
+fc = lambda m, n: m * m + n * n
+
+# By adding fa, fb, and fc above, we can get:
+# P = 2m(m + n)
+# which simplifies to
+# n = P / (2m) - m
+fn = lambda m: 500.0 / m - m
+
+# Solving for fn = 0 above, we find that m cannot be greater than sqrt(500)
+# (about 22.3) or else n becomes negative.
+for m in range(1, 23):
+ n = fn(m)
+ if n == int(n) and m > n:
+ print("(%i, %i, %i)" % (fa(m, n), fb(m, n), fc(m, n)))
+ print("Answer: %i" % (fa(m, n) * fb(m, n) * fc(m, n)))
+ exit(0)
View
12 9/jonm.py
@@ -0,0 +1,12 @@
+#!/usr/bin/python
+
+import math
+import sys
+