generated from janezicmatej/aoc-template
29 lines
477 B
Rust
29 lines
477 B
Rust
#![feature(pattern)]
|
|
|
|
use std::mem::swap;
|
|
|
|
pub mod parsers;
|
|
pub mod template;
|
|
|
|
pub fn lcm(first: usize, second: usize) -> usize {
|
|
first * second / gcd(first, second)
|
|
}
|
|
|
|
pub fn gcd(first: usize, second: usize) -> usize {
|
|
let mut max = first;
|
|
let mut min = second;
|
|
if min > max {
|
|
swap(&mut min, &mut max)
|
|
}
|
|
|
|
loop {
|
|
let res = max % min;
|
|
if res == 0 {
|
|
return min;
|
|
}
|
|
|
|
max = min;
|
|
min = res;
|
|
}
|
|
}
|