summary refs log tree commit diff homepage
path: root/2017/src/bin
diff options
context:
space:
mode:
authorJune McEnroe <programble@gmail.com>2017-12-09 02:50:05 -0500
committerJune McEnroe <programble@gmail.com>2017-12-09 02:50:05 -0500
commit2368fef619c053175eda97fac09f3b4e9e505386 (patch)
tree8a3c53df1f965a4301ce72cec8950d0062d088bb /2017/src/bin
parentDay 7, part 2 (diff)
downloadaoc-2368fef619c053175eda97fac09f3b4e9e505386.tar.gz
aoc-2368fef619c053175eda97fac09f3b4e9e505386.zip
Day 8
Diffstat (limited to '2017/src/bin')
-rw-r--r--2017/src/bin/day08.rs57
1 files changed, 57 insertions, 0 deletions
diff --git a/2017/src/bin/day08.rs b/2017/src/bin/day08.rs
new file mode 100644
index 0000000..e5a9ad0
--- /dev/null
+++ b/2017/src/bin/day08.rs
@@ -0,0 +1,57 @@
+use std::collections::HashMap;
+use std::io::{self, Read};
+
+fn solve1(input: &str) -> i32 {
+    let mut regs = HashMap::new();
+    for line in input.lines() {
+        let mut words = line.split_whitespace();
+        let dest = words.next().unwrap();
+        let op = words.next().unwrap();
+        let val = words.next().unwrap();
+        assert_eq!(Some("if"), words.next());
+        let src = words.next().unwrap();
+        let cmp = words.next().unwrap();
+        let rhs = words.next().unwrap();
+
+        let mut val: i32 = val.parse().unwrap();
+        if op == "dec" {
+            val = -val;
+        }
+        let rhs: i32 = rhs.parse().unwrap();
+        let src = *regs.entry(src.to_owned()).or_insert(0);
+        let dest = regs.entry(dest.to_owned()).or_insert(0);
+
+        let cond = match cmp {
+            "==" => src == rhs,
+            "!=" => src != rhs,
+            "<=" => src <= rhs,
+            ">=" => src >= rhs,
+            "<" => src < rhs,
+            ">" => src > rhs,
+            _ => unimplemented!(),
+        };
+        if cond {
+            *dest += val;
+        }
+    }
+    regs.values().cloned().max().unwrap()
+}
+
+fn main() {
+    let mut input = String::new();
+    io::stdin().read_to_string(&mut input).unwrap();
+
+    println!("Part 1: {}", solve1(&input));
+}
+
+#[test]
+fn part1() {
+    assert_eq!(1, solve1(
+"\
+b inc 5 if a > 1
+a inc 1 if b < 5
+c dec -10 if a >= 1
+c inc -20 if c == 10
+"
+    ));
+}
ef='/src/commit/www/photo.causal.agency/2024-09-22/lens?id=1215130a85ee9abe70d2e2c8af4eb0be368f4294&follow=1'>Add photos from September 22June McEnroe 2024-09-25Add photos from September 15June McEnroe 2024-09-24Add photos from September 14June McEnroe 2024-09-24Add photos from September 12June McEnroe 2024-09-24Add photos from September 7June McEnroe 2024-09-24Allow not having descriptionsJune McEnroe I'm sorry, I can't keep writing descriptions. It makes posting photos take too long, I often don't know the words for what I'm looking at, and a good description is an entirely different work of art than the photo I took, and I'm just a photographer. It's visual art. 2024-09-23Automatically select the last used lens for a bodyJune McEnroe 2024-09-19Add photos from September 5June McEnroe Had to prefix the folder number onto these file names manually because they must have come out of a different scanner or something. 2024-09-15Add some more film stocks to the listJune McEnroe 2024-09-13Add photos from September 2June McEnroe 2024-09-13Add Fomapan 200 to films listJune McEnroe 2024-09-10Add August 29 picnic photosJune McEnroe 2024-09-08Apply some bold to trips renderingJune McEnroe This seems easier to visually scan. The only other thing I'd like is a nicer date rendering but JavaScript is useless for that. 2024-09-08Render trips hopefully more efficientlyJune McEnroe 2024-09-08Allow removing bodies and lensesJune McEnroe 2024-09-08Limit body width so it looks less silly on desktopJune McEnroe 2024-09-07Handle no film being loadedJune McEnroe 2024-09-07Fancy up the text a littleJune McEnroe