From a24ae8e1d314e20a049f07179162f21378574b17 Mon Sep 17 00:00:00 2001 From: Martin Ashby Date: Sun, 25 Dec 2022 21:28:52 +0000 Subject: reorder tests in day25 --- src/day25.rs | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/day25.rs b/src/day25.rs index 2d26028..af5f15e 100644 --- a/src/day25.rs +++ b/src/day25.rs @@ -16,6 +16,26 @@ fn from_snafu(s: &str) -> i64 { i } +fn to_snafu(mut i: i64) -> String { + // how to do this :thinking: add two, mod 5,take away 2? // nope + let mut res = Vec::::new(); + while i != 0 { + let d = ((i + 2) % 5) - 2; + let ch = match d { + 2 => '2', + 1 => '1', + 0 => '0', + -1 => '-', + -2 => '=', + _ => panic!("unexpected digit {}", d) + }; + res.push(ch); + i = (i + 2) / 5; + } + res.reverse(); + res.into_iter().collect::() +} + #[cfg(test)] mod tests { use super::*; @@ -44,27 +64,6 @@ mod tests { } } -fn to_snafu(mut i: i64) -> String { - // how to do this :thinking: add two, mod 5,take away 2? // nope - let mut res = Vec::::new(); - while i != 0 { - let d = ((i + 2) % 5) - 2; - let ch = match d { - 2 => '2', - 1 => '1', - 0 => '0', - -1 => '-', - -2 => '=', - _ => panic!("unexpected digit {}", d) - }; - res.push(ch); - i = (i + 2) / 5; - } - res.reverse(); - res.into_iter().collect::() - -} - pub fn run(input: String) { let s: i64 = input.lines() .map(from_snafu) -- cgit v1.2.3-ZIG