summary refs log tree commit diff homepage
path: root/src/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2016-12-04 18:50:15 -0500
committerJune McEnroe <june@causal.agency>2020-11-22 00:13:50 -0500
commite94a2eb70482a255ba9fcd7fc42e099a777d4c5f (patch)
tree0249ee86f9c04baa2ba7a63902d7f2d5288e7603 /src/bin
parentDay 4 part 2 (diff)
downloadaoc-e94a2eb70482a255ba9fcd7fc42e099a777d4c5f.tar.gz
aoc-e94a2eb70482a255ba9fcd7fc42e099a777d4c5f.zip
Use math to rotate in day 4
Diffstat (limited to '')
-rw-r--r--src/bin/day04.rs13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/bin/day04.rs b/src/bin/day04.rs
index c6a9709..8e724c2 100644
--- a/src/bin/day04.rs
+++ b/src/bin/day04.rs
@@ -64,15 +64,12 @@ impl Room {
 }
 
 fn rotate(c: char, n: u32) -> char {
-    let mut c = c;
-    for _ in 0..n {
-        c = match c {
-            'a' ... 'y' => (c as u8 + 1) as char,
-            'z' => 'a',
-            _ => panic!("cannot rotate {}", c),
-        }
+    let c = c as u8 + (n % 26) as u8;
+    if c > b'z' {
+        (c - 26) as char
+    } else {
+        c as char
     }
-    c
 }
 
 fn solve1(input: &str) -> u32 {