Permalink
Browse files

Solve problem 85

  • Loading branch information...
1 parent 11c8279 commit ca123ff5a29699163508ae2c7a98c1fb4af45535 Austin Lee committed Apr 6, 2012
Showing with 40 additions and 0 deletions.
  1. +38 −0 src/problem-85/mmla.rb
  2. +2 −0 src/problem-85/problem
View
38 src/problem-85/mmla.rb
@@ -0,0 +1,38 @@
+public
+
+# we aren't going to brute force it, rather, use an table and a well calculated formula
+# that is, it keeps going up in an arithmetic pattern
+# x 1 2 3 4 5 6
+# y X------------------
+# 1 | 1 3 6 10 15 21
+# 2 | 3 9 18 30 45
+# 3 | 6 18
+# 4 | 10 30
+# 5 | 15 45
+# 6 | 21
+def mmla
+ theRoots = Array.new
+ n = 0
+ i = 1
+ begin
+ n += i
+ theRoots.push n
+ i += 1
+ end while n*3 < 2000000
+ result = 0
+ smallest = 1000
+ # to get the values of teh chart using x, y
+ # intArithmeticSequenceValues(x, theRoots[y-1], x * theRoots[y-1)
+ theRoots.each do |r|
+ i = 1
+ begin
+ n = intArithmeticSequenceValues(i, r, i*r)
+ if (2000000-n).abs < smallest
+ smallest = (2000000-n).abs
+ result = i * (theRoots.index(r) + 1)
+ end
+ i += 1
+ end while n < 2000000
+ end
+ result
+end
View
2 src/problem-85/problem
@@ -0,0 +1,2 @@
+By counting carefully it can be seen that a rectangular grid measuring 3 by 2 contains eighteen rectangles:
+Although there exists no rectangular grid that contains exactly two million rectangles, find the area of the grid with the nearest solution.

0 comments on commit ca123ff

Please sign in to comment.