Created
August 1, 2013 12:33
-
-
Save ackintosh/6130925 to your computer and use it in GitHub Desktop.
problem 5. http://projecteuler.net/problem=5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def flat? | |
self.each do |n| | |
return false unless first == n | |
end | |
true | |
end | |
end | |
def lcm(a, b) | |
ar1 = [a, b] | |
ar2 = ar1.dup | |
while ar1.flat? == false do | |
index_of_min = ar1.index(ar1.min) | |
ar1[index_of_min] += ar2[index_of_min] | |
end | |
ar1.first | |
end | |
n = 1 | |
(1..20).each do |i| | |
n = lcm(n, i) | |
end | |
p n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment