summary refs log tree commit diff homepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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 {
/td>Simplify temp trap in upJune McEnroe 2019-02-17Add line numbers to hiJune McEnroe Renames previous -n option to -m to stay consistent with cat -n. Prefixing lines with line numbers affects where the first tab indent ends up relative to the text above it. Not sure if it's worth fixing somehow. 2019-02-17Always split spans after newlinesJune McEnroe Simplifies ANSI and IRC output code, and prepares for line numbered output. 2019-02-15Color format specifiers light cyan in vimJune McEnroe 2019-02-15Highlight Interp as yellowJune McEnroe 2019-02-15Highlight strings in sh command substitutionsJune McEnroe 2019-02-15Add nmap gpJune McEnroe 2019-02-14Avoid newline when copying URL to pasteboardJune McEnroe 2019-02-13Add forgotten "sixth" book of H2G2June McEnroe