From e94a2eb70482a255ba9fcd7fc42e099a777d4c5f Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sun, 4 Dec 2016 18:50:15 -0500 Subject: Use math to rotate in day 4 --- src/bin/day04.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src') 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 { -- cgit 1.4.1 ontfiles
summary refs log tree commit diff
path: root/bin/modem.c (unfollow)
Commit message (Expand)Author
2019-02-18Match whitespace between * [] {}June McEnroe
2019-02-18Fix function-like #define regexJune McEnroe
2019-02-18Match Tag in RustJune McEnroe
2019-02-18Match sh functions as TagJune McEnroe
2019-02-18Match Sh and Ss as Tag in mdocJune McEnroe
2019-02-18Match statics and typedefs as TagJune McEnroe
2019-02-18Clean up htmlHeaderJune McEnroe
2019-02-18Remove hi line numberingJune McEnroe
2019-02-18Add Tag class to hiJune McEnroe
2019-02-17Generate HTML with hi -n -f html -o anchorJune McEnroe
2019-02-17Add hi -f html -o anchor for line number linksJune McEnroe
2019-02-17Simplify temp trap in upJune McEnroe
2019-02-17Add line numbers to hiJune McEnroe
2019-02-17Always split spans after newlinesJune McEnroe
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