From 3b4a4561e2cc8b5b614e7fdd819109eb5d75fea0 Mon Sep 17 00:00:00 2001 From: June 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(-) 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 commit diff homepage
path: root/merge.c (unfollow)
Commit message (Expand)Author
2018-07-25Set client sockets SNDBUF to twice tile sizeJune McEnroe
2018-07-24Revert "Do not set non-blocking on client sockets"June McEnroe
2018-07-24Print time_t with %jd in metaJune McEnroe
2018-07-24Do not set non-blocking on client socketsJune McEnroe
2018-07-24Use EV_SETJune McEnroe
2018-07-24Link with -lcursesJune McEnroe
2018-07-23Fix NaNs in serverMapJune McEnroe
2018-07-22Add libm.so to chroot.tarJune McEnroe
2018-07-22Link with -lmJune McEnroe
2018-07-22Add map to clientJune McEnroe
2018-07-21Refactor readInput for each modeJune McEnroe
2018-07-19Add ARRAY_LEN macroJune McEnroe
2018-07-17Add server map generationJune McEnroe
2018-07-17Tabify sourceJune McEnroe
2018-05-13Fix ncurses color pair numberingJune McEnroe
2018-04-09Use anonymous unionJune McEnroe
2018-04-09Replace #define with enum or const where possibleJune McEnroe
2018-03-31Link against ncursesJune McEnroe
2018-03-05Miscellaneous code cleanupJune McEnroe
2018-03-05Pass message structs by valueJune McEnroe
2018-03-05Use stdio in merge and metaJune McEnroe
2018-03-05Clean up spawn constantsJune McEnroe
2018-03-05Rename Tile timestamps {create,modify,access}TimeJune McEnroe
2018-03-05Pack message type enumsJune McEnroe
2018-03-05Undef COLOR_ constants in torus.hJune McEnroe
2018-03-05Generate tagsJune McEnroe
2017-10-03Simplify Makefile with pattern ruleJune McEnroe
2017-09-27Remove leading blank linesJune McEnroe
2017-09-27Add merge.c to READMEJune McEnroe
2017-09-03Assert client coords are valid after movementJune McEnroe
2017-09-03Relicense AGPLJune McEnroe
2017-09-01Revert "Add client readOnly mode"June McEnroe
2017-09-01Remove clientRemove call from clientCastJune McEnroe
2017-09-01Add client readOnly modeJune McEnroe
2017-08-31Clean up merge toolJune McEnroe
2017-08-31Choose B for tiles with equal modify timesJune McEnroe
2017-08-31Add quick data file merge toolJune McEnroe
2017-08-30Use only foreground color for selecting spawnJune McEnroe
2017-08-29Add four additional spawnsJune McEnroe
2017-08-28Add respawningJune McEnroe
2017-08-26Move license above includesJune McEnroe
2017-08-26Snapshot metadataJune McEnroe
2017-08-26Add meta.c to READMEJune McEnroe
2017-08-26Use MakefileJune McEnroe