summary refs log tree commit diff homepage
path: root/src
diff options
context:
space:
mode:
authorJune McEnroe <programble@gmail.com>2016-12-04 18:50:15 -0500
committerJune McEnroe <programble@gmail.com>2016-12-04 18:50:15 -0500
commitf52473c78bb1eca124aa211b614c8fbfe7bf4b83 (patch)
tree2aae6933e48db2ca30bb56e98d279d55d59f2b79 /src
parentDay 4 part 2 (diff)
downloadaoc-f52473c78bb1eca124aa211b614c8fbfe7bf4b83.tar.gz
aoc-f52473c78bb1eca124aa211b614c8fbfe7bf4b83.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 {
l/commit/Makefile?h=2.2&id=70f627bc47e944a63f32fcf60db73913845772c6&follow=1'>Enable -Wmissing-prototypesJune McEnroe 2022-02-19Fix edit.[ch] license notice additional permissionsJune McEnroe 2022-02-19Run line editing testsJune McEnroe 2022-02-18Implement new line editing "library"June McEnroe 2022-02-18Simplify cursor positioning in inputJune McEnroe 2022-02-18Fix M-f orderingJune McEnroe 2022-02-12Move sandman build to scripts/MakefileJune McEnroe 2022-02-12Use compat_readpassphrase.c on LinuxJune McEnroe 2022-02-12Copy RPP defines from oconfigureJune McEnroe