From dd297f8c1ef88615fee1df562cf53747cc1aae71 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sat, 3 Dec 2016 22:43:01 -0500 Subject: Day 2 --- src/bin/day02.rs | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/bin/day02.rs (limited to 'src') diff --git a/src/bin/day02.rs b/src/bin/day02.rs new file mode 100644 index 0000000..c5a7f11 --- /dev/null +++ b/src/bin/day02.rs @@ -0,0 +1,71 @@ +use std::io::{self, Read}; + +#[derive(Debug, Clone, Copy)] +enum Keypad { + K1, K2, K3, + K4, K5, K6, + K7, K8, K9, +} + +impl Keypad { + fn up(self) -> Self { + use Keypad::*; + match self { + K4 => K1, K5 => K2, K6 => K3, + K7 => K4, K8 => K5, K9 => K6, + _ => self, + } + } + + fn down(self) -> Self { + use Keypad::*; + match self { + K1 => K4, K2 => K5, K3 => K6, + K4 => K7, K5 => K8, K6 => K9, + _ => self, + } + } + + fn left(self) -> Self { + use Keypad::*; + match self { + K2 => K1, K3 => K2, + K5 => K4, K6 => K5, + K8 => K7, K9 => K8, + _ => self, + } + } + + fn right(self) -> Self { + use Keypad::*; + match self { + K1 => K2, K2 => K3, + K4 => K5, K5 => K6, + K7 => K8, K8 => K9, + _ => self, + } + } +} + +fn main() { + let mut input = String::new(); + io::stdin().read_to_string(&mut input).unwrap(); + + let mut code = Vec::new(); + let mut key = Keypad::K5; + + for line in input.lines() { + for direction in line.chars() { + key = match direction { + 'U' => key.up(), + 'D' => key.down(), + 'L' => key.left(), + 'R' => key.right(), + _ => panic!("{} is not a direction", direction), + } + } + code.push(key); + } + + println!("Part 1: {:?}", code); +} -- cgit 1.4.1 src/log/etc?id=056c5dd2bbdee1f228f6fed3e4a2c324376caef1&follow=1'>etc/CodeQWERTY.bundle (unfollow)
Commit message (Expand)Author
2022-07-30Add Normal PeopleJune McEnroe
2022-07-26Rewrite glitch from new pngoJune McEnroe
2022-07-26Update Care with time-to-ID and piercingsJune McEnroe
2022-07-26Add -w to upJune McEnroe
2022-07-13Set push.autoSetupRemoteJune McEnroe
2022-07-08Remove TOURJune McEnroe
2022-07-03Add The Bone Shard EmperorJune McEnroe
2022-06-25Bump xterm font size to 12June McEnroe
2022-06-10Handle subshells (and functions) inside substitutionsJune McEnroe
2022-06-10Switch to jorts Install scriptJune McEnroe
2022-06-08Indicate if still reading or no resultsJune McEnroe
2022-06-08Add Maiden, Mother, CroneJune McEnroe
2022-06-05FIRST SHOW IN 2.5 YEARS BABEY!!!June McEnroe
2022-06-03Set line number on File linesJune McEnroe
2022-06-03Stop polling stdin after EOFJune McEnroe
2022-06-02Set TABSIZE=4June McEnroe
2022-06-02Do basic match highlightingJune McEnroe
2022-06-02Clean up parsing a littleJune McEnroe
2022-06-02Don't duplicate path stringJune McEnroe
2022-06-02Use stderr instead of /dev/tty, realloc buffer if lines too longJune McEnroe
2022-06-02Add initial working version of qfJune McEnroe
2022-05-29Set prompt for okshJune McEnroec/commit/home/.config/X/resources?id=70d13d203b7c6697f250b2752f332ebe04f50b50&follow=1'>Add macOS-like copy and paste to xtermJune McEnroe
2021-02-08Only update clock script every minuteJune McEnroe
2021-02-08Use 4M- for window resizing in cwmJune McEnroe
2021-02-08Tweak trackpad scaling, mouse accelerationJune McEnroe
2021-02-08Use xsel in up and add it do install.shJune McEnroe
2021-02-07Swap root window coloursJune McEnroe
2021-02-07Add -X flag to install X stuff on OpenBSDJune McEnroe
2021-02-07Adjust brightness by smaller incrementsJune McEnroe
2021-02-07Fix cwm window cycling, move big by defaultJune McEnroe
2021-02-07Use class names for Foreground, Background, BorderColorJune McEnroe
2021-02-07Add simple battery status and clock to xsessionJune McEnroe
2021-02-07Set cursor theme and sizeJune McEnroe
2021-02-07Use scrot for up -s if no screencaptureJune McEnroe
2021-02-07Enable mouse acceleration in XJune McEnroe
2021-02-07Set colours for Xt and cwmJune McEnroe
2021-02-07Set urgency on bell in xtermJune McEnroe
2021-02-07Add bindings for brightness controlJune McEnroe
2021-02-07Set X key repeat rateJune McEnroe
2021-02-07Bump font size to 12June McEnroe
2021-02-07Fully configure and rebind cwmJune McEnroe
2021-02-07Add BintiJune McEnroe
2021-02-07Finish configuring xtermJune McEnroe
2021-02-06Enable tapping, reverse scroll, set scaling in wsconsctlJune McEnroe
2021-02-06Set root window to black on purple snowJune McEnroe
2021-02-06Add xmodmap configurationJune McEnroe
2021-02-06Add initial OpenBSD X configurationJune McEnroe
2021-02-06Add xterm output to schemeJune McEnroe