summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2017-12-09 02:54:49 -0500
committerJune McEnroe <june@causal.agency>2020-11-22 00:14:25 -0500
commit3b4a4561e2cc8b5b614e7fdd819109eb5d75fea0 (patch)
tree7483e39fab08788bb59d97db63d5bc771149e5e8
parentDay 8 (diff)
downloadaoc-3b4a4561e2cc8b5b614e7fdd819109eb5d75fea0.tar.gz
aoc-3b4a4561e2cc8b5b614e7fdd819109eb5d75fea0.zip
Day 8, part 2
-rw-r--r--2017/src/bin/day08.rs27
1 files changed, 22 insertions, 5 deletions
diff --git a/2017/src/bin/day08.rs b/2017/src/bin/day08.rs
index e5a9ad0..4266d31 100644
--- a/2017/src/bin/day08.rs
+++ b/2017/src/bin/day08.rs
@@ -1,7 +1,8 @@
 use std::collections::HashMap;
 use std::io::{self, Read};
 
-fn solve1(input: &str) -> i32 {
+fn solve(input: &str) -> (i32, i32) {
+    let mut max = 0;
     let mut regs = HashMap::new();
     for line in input.lines() {
         let mut words = line.split_whitespace();
@@ -33,25 +34,41 @@ fn solve1(input: &str) -> i32 {
         if cond {
             *dest += val;
         }
+        if *dest > max {
+            max = *dest;
+        }
     }
-    regs.values().cloned().max().unwrap()
+    (regs.values().cloned().max().unwrap(), max)
 }
 
 fn main() {
     let mut input = String::new();
     io::stdin().read_to_string(&mut input).unwrap();
 
-    println!("Part 1: {}", solve1(&input));
+    println!("Part 1: {}", solve(&input).0);
+    println!("Part 2: {}", solve(&input).1);
 }
 
 #[test]
 fn part1() {
-    assert_eq!(1, solve1(
+    assert_eq!(1, solve(
+"\
+b inc 5 if a > 1
+a inc 1 if b < 5
+c dec -10 if a >= 1
+c inc -20 if c == 10
+"
+    ).0);
+}
+
+#[test]
+fn part2() {
+    assert_eq!(10, solve(
 "\
 b inc 5 if a > 1
 a inc 1 if b < 5
 c dec -10 if a >= 1
 c inc -20 if c == 10
 "
-    ));
+    ).1);
 }
der'>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