-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5.rb
More file actions
32 lines (27 loc) · 736 Bytes
/
5.rb
File metadata and controls
32 lines (27 loc) · 736 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
=begin
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?
=end
require "test/unit"
include Test::Unit::Assertions
def largest
i = 1
loop do
largest = 20 * i
return largest if
largest % 20 == 0 &&
largest % 19 == 0 &&
largest % 18 == 0 &&
largest % 17 == 0 &&
largest % 16 == 0 &&
largest % 15 == 0 &&
largest % 14 == 0 &&
largest % 13 == 0 &&
largest % 12 == 0 &&
largest % 11 == 0
# numbers evenly divisible by 11 until 20 are
# also evenly divisible by all smaller numbers
i +=1
end
end
assert largest == 232792560