summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Ashby <martin@ashbysoft.com>2022-12-25 21:28:52 +0000
committerMartin Ashby <martin@ashbysoft.com>2022-12-25 21:28:52 +0000
commita24ae8e1d314e20a049f07179162f21378574b17 (patch)
tree50eb5fbaf7f688ff6d1678a33c4287c951f7a718 /src
parent4636c264b8547acfec3bf7cf0579537f1997cadc (diff)
downloadaoc2022-main.tar.gz
aoc2022-main.tar.bz2
aoc2022-main.tar.xz
aoc2022-main.zip
reorder tests in day25HEADmain
Diffstat (limited to 'src')
-rw-r--r--src/day25.rs41
1 files 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::<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)