Skip to content

Problem 5: Smallest multiple

Link to the problem: https://projecteuler.net/problem=5.

Problem 5

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?

A simple solution

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
(defwire main-wire
  20 = .max
  1 >= .result

  (ForRange
   1 .max
   (-> >= .n
       .result >= .previous
       (When
        (-> .result (Math.Mod .n) (IsMore 0))
        (Repeat
         (-> .result (Math.Add .previous) > .result)
         :Forever true
         :Until (-> .result (Math.Mod .n) (Is 0))))))

  .result (Assert.Is 232792560 true)
  (Log "Answer"))

(defmesh root)
(schedule root main-wire)
(run root)
[info] [2023-02-24 14:01:41.774] [T-7028] [logging.cpp::62] [main-wire] Answer: 232792560

More details on the Project Euler's website: https://projecteuler.net/overview=005.