Problem 11 is yet another search. I used
transpose . zipWith drop [0..]
to get a quarter of the diagonals, and combined it with various uses of reverse
to get the rest of the diagonals. The result was on a diagonal.My solution to problem 12 was horribly slow with hugs, so I solved it in Java. The algorithm I used should be O(N3/2), and the answer I got was between 50 million and 100 million. Perhaps my calculation of triangle numbers was O(N2) in hugs, instead of O(N), causing the calculation to be O(N5/2).
Problem 13 might have been more of a challenge when restricted to fixed size integer arithmetic. As it was,
take 10 . show . sum
.My Haskell solution to problem 14 was horribly slow, so I solved it in Java by tabulating the results under a million and using the recursive formula whenever it went over a million.
My Haskell solution to problem 15 was horribly slow, so I solved it in Java by tabulating the results by building on the previously tabulated results for smaller grids, which should be O(N2).
Problem 16, like problem 13, was a simple one-liner that would have been much more difficult when restricted to fixed size integers.
Problem 17 is just a matter of counting correctly, without any nontrivial mathematical reasoning or computation.
Problem 18 (and problem 67) can be solved with pretty much a one-liner:
foldr1 (\ row sums -> zipWith3 (\ i l r -> i + max l r) row sums (tail sums))
.Problem 19 is an easy brute-force iteration, with only 1200 months to consider. The 100 and 400 year rules can be ignored, given the range.
Problem 20 is a simple one-liner just like problem 16, where the challenge is mainly for those restricted to fixed-size integers.
No comments:
Post a Comment