-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp5.lua
More file actions
33 lines (28 loc) · 851 Bytes
/
p5.lua
File metadata and controls
33 lines (28 loc) · 851 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
33
#!/usr/bin/env lua
--[[
2,520 is the smallest number that can be divided by each of the numbers
from 1 to 20 without any remainder.
What is the smallest positive number that is evenly divisible by all of
the numbers from 1 to 20?
]]
--- Determine if a number is divisible by 1, 2, ..., 20.
---@param n number The number to check the divisibility of.
local function is_evenly_disible(n)
for j = 2, 20 do
if n % j ~= 0 then
return false
end
end
return true
end
--- Determine the smallest number evenly divisible by 1, 2, ..., 20.
local function smallest_evenly_disible()
local step_size = 2 * 3 * 5 * 7 * 11 * 13 * 17 * 19
local i = step_size
while not is_evenly_disible(i) do
i = i + step_size
end
return i
end
-- Compute solution
print(smallest_evenly_disible()) -- 232,792,560