Rust Implementation of Problem 5
View source code here on GitHub!
Problem Solution
- pub fn problems::p0005::p0005() -> utils::Answer
1/*
2Project Euler Problem 5
3
4I solved this problem by testing all combinations of the various multiples. I
5actually tried to solve this by hand before doing this, and it wasn't terribly
6hard. The answer turns out to be (2**4 * 3**2 * 5 * 7 * 11 * 13 * 17 * 19)
7
8Problem:
9
102520 is the smallest number that can be divided by each of the numbers from 1
11to 10 without any remainder.
12
13What is the smallest positive number that is evenly divisible by all of the
14numbers from 1 to 20?
15*/
16use itertools::Itertools;
17
18use crate::include::utils::Answer;
19
20pub fn p0005() -> Answer {
21 let mut answer = u64::MAX;
22 let group = 1..=20u64;
23 for x in group.clone() {
24 for multiples in group.clone().combinations(x as usize) {
25 let num = multiples.into_iter().product();
26 if num < answer && group.clone().all(|divisor| num % divisor == 0) {
27 answer = num;
28 }
29 }
30 }
31 return Answer::Int(answer.into());
32}