Day 13, puzzle 2
This commit is contained in:
24
src/bin/d13p2.rs
Normal file
24
src/bin/d13p2.rs
Normal file
@ -0,0 +1,24 @@
|
||||
use aoc22::{
|
||||
day13::{self, Node},
|
||||
util,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
|
||||
pub fn main() {
|
||||
let mut pairs = day13::parse_pairs(&util::parse_input());
|
||||
let mut packets = Vec::new();
|
||||
while let Some(pair) = pairs.pop() {
|
||||
packets.push(pair.0);
|
||||
packets.push(pair.1);
|
||||
}
|
||||
let div1 = Node::List(vec![Node::List(vec![Node::Num(2)])]);
|
||||
let div2 = Node::List(vec![Node::List(vec![Node::Num(6)])]);
|
||||
packets.push(div1.clone());
|
||||
packets.push(div2.clone());
|
||||
|
||||
packets.sort();
|
||||
let n1 = packets.iter().find_position(|p| **p == div1).unwrap().0 + 1;
|
||||
let n2 = packets.iter().find_position(|p| **p == div2).unwrap().0 + 1;
|
||||
|
||||
println!("Decoder key: {}", n1 * n2);
|
||||
}
|
||||
Reference in New Issue
Block a user