Thursday, November 4, 2010

Euler Project

I'm doing problems from the Euler Project just now. My code is hideously embarrassing, but it's all my own and I'm kinda proud that I can write the stuff at all, considering that less than a month ago I might've looked at the problems and despaired, or at least made headway much more slowly.

My profile: http://projecteuler.net/profile/geeklinda.png I wish it said which specific problems I've solved...
  1. http://pastie.org/1273530 An alternate and very elegant solution from rancorbeast ((1..(1000 - 1)).reject { |i| i % 5 != 0 && i % 3 != 0 }).inject(0) {|a, b| a + b}
  2. http://pastie.org/1273527
  3. http://pastie.org/1273740
  4. http://pastie.org/1285750
  5. http://pastie.org/1290420 Code blatantly stolen from 17 Sep 2005 03:20 am post by Olath at http://projecteuler.net/index.php?section=forum&id=5 (can't access if you haven't already solved the problem) ... yes there is a discrepancy here. :)
  6. http://pastie.org/1285746
  7. http://pastie.org/1293957 (stolen from forums after getting answer)
  8. http://pastie.org/1285739
  9. http://pastie.org/1293953 (All mine. I'm proud of it. It runs pretty quickly. finding an answer took me several tries for some reason.)
    rancorbeast beat me by miles with the oneliner below.
    (1..500).each {|i| (i..500).each {|j| if i + j + Math.sqrt(i ** 2 + j ** 2) == 1000; print i * j * Math.sqrt(i ** 2 + j ** 2); end } }
  10. solved in python.
Euler 11..n will be in a new post.