aoc2022

Advent of Code 2022 solutions in Rust
git clone git://code.mfashby.net:/aoc2022
Log | Files | Refs

commit a24ae8e1d314e20a049f07179162f21378574b17
parent 4636c264b8547acfec3bf7cf0579537f1997cadc
Author: Martin Ashby <martin@ashbysoft.com>
Date:   Sun, 25 Dec 2022 21:28:52 +0000

reorder tests in day25

Diffstat:
Msrc/day25.rs | 41++++++++++++++++++++---------------------
1 file changed, 20 insertions(+), 21 deletions(-)

diff --git 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::<char>::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::<String>() +} + #[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::<char>::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::<String>() - -} - pub fn run(input: String) { let s: i64 = input.lines() .map(from_snafu)