Commit b4749125 authored by Kai Brandes's avatar Kai Brandes

better types as input for 3a

parent 5abbdd15
......@@ -13,8 +13,7 @@ fn rel_position_and_circle(pos: &u32) -> (u32, u32) {
(c.abs() as u32 - 1, circle_nr)
}
pub fn calc_day_3_a(input: String) -> u32 {
let position = input.parse::<u32>().unwrap();
pub fn calc_day_3_a(position: u32) -> u32 {
let (rel_pos, circle_nr) = rel_position_and_circle(&position);
let width = 1 + circle_nr * 2;
((width / 2) as f32 - ((rel_pos + 1) % (width -1)) as f32).abs() as u32 + (width / 2)
......@@ -28,23 +27,23 @@ mod tests {
#[test]
fn it_calcs_some_distances() {
assert_eq!(2, calc_day_3_a(String::from("11")));
assert_eq!(3, calc_day_3_a(String::from("12")));
assert_eq!(4, calc_day_3_a(String::from("13")));
assert_eq!(2, calc_day_3_a(String::from("15")));
assert_eq!(2, calc_day_3_a(String::from("19")));
assert_eq!(3, calc_day_3_a(String::from("10")));
assert_eq!(6, calc_day_3_a(String::from("49")));
assert_eq!(6, calc_day_3_a(String::from("37")));
assert_eq!(6, calc_day_3_a(String::from("31")));
assert_eq!(2, calc_day_3_a(String::from("23")));
assert_eq!(430, calc_day_3_a(String::from("312051")));
assert_eq!(38, calc_day_3_a(String::from("2343")));
assert_eq!(34, calc_day_3_a(String::from("1411")));
assert_eq!(123, calc_day_3_a(String::from("23134")));
assert_eq!(22, calc_day_3_a(String::from("1111")));
assert_eq!(610, calc_day_3_a(String::from("987653")));
assert_eq!(880, calc_day_3_a(String::from("1134411")));
assert_eq!(2, calc_day_3_a(11));
assert_eq!(3, calc_day_3_a(12));
assert_eq!(4, calc_day_3_a(13));
assert_eq!(2, calc_day_3_a(15));
assert_eq!(2, calc_day_3_a(19));
assert_eq!(3, calc_day_3_a(10));
assert_eq!(6, calc_day_3_a(49));
assert_eq!(6, calc_day_3_a(37));
assert_eq!(6, calc_day_3_a(31));
assert_eq!(2, calc_day_3_a(23));
assert_eq!(430, calc_day_3_a(312051));
assert_eq!(38, calc_day_3_a(2343));
assert_eq!(34, calc_day_3_a(1411));
assert_eq!(123, calc_day_3_a(23134));
assert_eq!(22, calc_day_3_a(1111));
assert_eq!(610, calc_day_3_a(987653));
assert_eq!(880, calc_day_3_a(1134411));
}
#[test]
......
......@@ -30,5 +30,5 @@ pub fn day_2_b() -> u32 {
}
pub fn day_3_a() -> u32 {
return day3::calc_day_3_a(String::from("312051"));
return day3::calc_day_3_a(312051);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment