Dec 11th, 2022 under Programming Rust Advent of Code
Non-recursive least common multiple function for multiple (vec) numbers in Rust.
/// Least common multiple vec of numbers fn lcm(numbers: Vec<u64>) -> u64 { let mut temp = numbers.clone(); // check all the same loop { let mut same = true; for idx in 1..temp.len() { if temp[0] != temp[idx] { same = false; break; } } if same { return temp[0]; } // Find lowest index match temp.iter().enumerate().min_by(|(_, a), (_, b)| a.cmp(b)).map(|(index, _)| index) { Some(idx) => { temp[idx] = temp[idx] + numbers[idx]; }, None => panic!("Not possible") } } }