From 9b80143e3720d24c16c0db79cf0b83f6e7593dbd Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Thu, 15 Dec 2022 14:39:10 -0600 Subject: [PATCH] Day 13 part 2 done --- 2022/rust/src/day13.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/2022/rust/src/day13.rs b/2022/rust/src/day13.rs index a1b233e..a4b72e5 100644 --- a/2022/rust/src/day13.rs +++ b/2022/rust/src/day13.rs @@ -136,7 +136,29 @@ fn part1(input: &Input) -> Answer { } fn part2(input: &Input) -> Answer { - 0 + let mut packets = vec![]; + for pair in input { + packets.push(&pair.left); + packets.push(&pair.right); + } + let d1 = "[[2]]".parse::().unwrap(); + let d2 = "[[6]]".parse::().unwrap(); + packets.push(&d1); + packets.push(&d2); + packets.sort(); + let mut di1 = 0; + let mut di2 = 0; + let mut i = 1; + for p in packets { + if p == &d1 { + di1 = i; + } + if p == &d2 { + di2 = i; + } + i += 1; + } + di1 * di2 } fn main() { @@ -195,7 +217,7 @@ mod tests { ); let input = processed_input(TEST_INPUT); assert_eq!(part1(&input), 13); - assert_eq!(part2(&input), 0); + assert_eq!(part2(&input), 140); // assert_eq!(both_parts(&input), (0, 0)); } }