Skip to content

Instantly share code, notes, and snippets.

@atushi
Created July 14, 2013 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atushi/5993371 to your computer and use it in GitHub Desktop.
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?
$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