summary refs log tree commit diff homepage
path: root/2017/src/bin
diff options
context:
space:
mode:
Diffstat (limited to '2017/src/bin')
-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);
 }
ort HTTP PUT in upJune McEnroe 2021-09-22Remove default faviconJune McEnroe 2021-09-21Use Z_FILTERED strategyJune McEnroe 2021-09-21Recalculate various lengths only as neededJune McEnroe 2021-09-21Rewrite pngo, add explicit optionsJune McEnroe 2021-09-16Fix /* **/ comment matchingJune McEnroe 2021-09-15Remove typer, add downgrade to READMEJune McEnroe 2021-09-15Set bot mode on downgradeJune McEnroe 2021-09-15Enter capsicum in downgradeJune McEnroe 2021-09-15Factor out common parts of downgrade messagesJune McEnroe 2021-09-14Add downgrade IRC botJune McEnroe 2021-09-14Sort by title if authors matchJune McEnroe 2021-09-13Swap-remove tags as they're foundJune McEnroe 2021-09-12Replace htagml regex with strncmpJune McEnroe 2021-09-11Also defer printing comment for lone close-parensJune McEnroe 2021-09-10Publish "git-comment"June McEnroe 2021-09-10Add git comment --pretty optionJune McEnroe 2021-09-08Defer printing comment if line is blank or closing braceJune McEnroe 2021-09-08Up default min-repeat to 30 linesJune McEnroe 2021-09-08Handle dirty lines in git-commentJune McEnroe 2021-09-08Document and install git-commentJune McEnroe 2021-09-08Add repeat and all options to git-commentJune McEnroe 2021-09-08Add group threshold to git-commentJune McEnroe