Lazy Evaluation

Marina's coding (mis)adventures

Browse by Tags

All Tags » ruby » euler (RSS)
euler problem #5
What is the smallest number that is evenly divisible by all of the numbers from 1 to 20? ---- To solve this problem easily, we need to remember that the smallest number that is evenly divisible by two numbers is their least common multiple. Armed with...

Posted Thursday, May 01, 2008 9:40 PM by mfedner | with no comments

Filed under: ,

Euler Problem 4
Find the largest palindrome made from the product of two 3-digit numbers. ----- First, I defined a palindrome recursively: a number is one if its first and last digits are the same, and if the inside is also a palindrome. def palindrome?(digitArr) if...

Posted Tuesday, April 08, 2008 8:35 PM by mfedner | with no comments

Filed under: ,

Euler Problem 3
What is the largest prime factor of the number 600851475143 ? ----- I wrote this piece of disgusting, un-Rubylike Ruby to get the answer by creating a list of a number's prime factors: def factor(composite) i=1 flag=false primefactors =[] while (i...

Posted Tuesday, April 08, 2008 8:07 PM by mfedner | with no comments

Filed under: , ,

Project Euler: Problem 2
The problem: Find the sum of all the even-valued terms in the [Fibonacci] sequence which do not exceed four million. Here's my fibonacci function: def fib(limit =nil) f1 = 0 f2 = 1 while (not limit or f2 <= limit) yield f2 f1,f2 = f2, f1+f2 end...

Posted Sunday, April 06, 2008 7:55 PM by mfedner | with no comments

Filed under: ,

Project Euler in Ruby
I'm taking Bill Wagner up on his Project Euler challenge , but in Ruby. I've secretly wanted to learn Ruby for a long time, and this looks like the perfect chance. So if my code makes your eyes bleed, it's cause I'm a total n00b. Without...

Posted Sunday, April 06, 2008 1:31 PM by mfedner | with no comments

Filed under: ,