From 5dab9fee2c1d86adf13a14650cbaeb3d5b9862e8 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Sat, 9 Dec 2017 02:54:49 -0500 Subject: Day 8, part 2 --- 2017/src/bin/day08.rs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to '2017/src/bin') 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); } -- cgit 1.4.1 alue='1839cfb23e671c5bc577bb583363a0e31046f5e2'/>
path: root/bin/1sh/libedit/histedit.h (unfollow)
Commit message (Expand)Author
2019-09-05Handle lack of Content-TypeJune McEnroe
2019-09-05Use CURLINFO_CONTENT_TYPEJune McEnroe
2019-09-05Decode entities in titlesJune McEnroe
2019-09-05Print title as soon as it's availableJune McEnroe
2019-09-05Use CURL_PREFIX to set flagsJune McEnroe
2019-09-05Add titleJune McEnroe
2019-09-04Add Avorter n'est pas tuerJune McEnroe
2019-08-29Unset executable on shell scriptsJune McEnroe
2019-08-29Add long-missing setopt to bin.7June McEnroe
2019-08-29Add editJune McEnroe