summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
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)