Created
July 14, 2013 06:15
-
-
Save atushi/5993371 to your computer and use it in GitHub Desktop.
Project Euler . Problem 5 . Smallest multiple : 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
This file contains 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
$MAXNUM = 20 | |
$target = [$MAXNUM] | |
$x = $MAXNUM | |
p 'Target : ' + $x.to_s | |
while $x >= 2 | |
if $MAXNUM % $x != 0 then | |
$target.push($x) | |
p 'Target : ' + $x.to_s | |
end | |
$x -= 1 | |
end | |
$answer = $MAXNUM | |
loop do | |
flag = true | |
$x = 0 | |
while $x<$target.length | |
if $answer % $target[$x] != 0 then | |
flag = false | |
break | |
end | |
$x += 1 | |
end | |
break if flag | |
$answer += $MAXNUM | |
end | |
p $answer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment