diff --git a/2019/src/bin/puzzle_10.rs b/2019/src/bin/puzzle_10.rs index 6fc1b33..4073176 100644 --- a/2019/src/bin/puzzle_10.rs +++ b/2019/src/bin/puzzle_10.rs @@ -3,6 +3,7 @@ use std::collections::HashMap; use std::io; use aoc2019::grid::Point; +use aoc2019::num; #[derive(Ord, PartialOrd, Eq, PartialEq)] struct AsteroidMetadata { @@ -10,14 +11,8 @@ struct AsteroidMetadata { distance: u32, } -fn gcd(mut a: i32, mut b: i32) -> i32 { - while b != 0 { - let t = b; - b = a % b; - a = t; - } - - a.abs() +fn gcd(a: i32, b: i32) -> i32 { + num::gcd(a.into(), b.into()).try_into().unwrap() } fn distances_from( diff --git a/2019/src/lib.rs b/2019/src/lib.rs index be0e145..d80e898 100644 --- a/2019/src/lib.rs +++ b/2019/src/lib.rs @@ -1,3 +1,4 @@ pub mod grid; pub mod intcode; pub mod iter; +pub mod num; diff --git a/2019/src/num.rs b/2019/src/num.rs new file mode 100644 index 0000000..9b23186 --- /dev/null +++ b/2019/src/num.rs @@ -0,0 +1,9 @@ +pub fn gcd(mut a: i64, mut b: i64) -> u64 { + while b != 0 { + let t = b; + b = a % b; + a = t; + } + + a.abs().try_into().unwrap() +}