add day 13, part 2
This commit is contained in:
parent
a8e74eae93
commit
3c0336b872
|
@ -16,7 +16,7 @@
|
||||||
use std::cmp::{Ordering, PartialOrd};
|
use std::cmp::{Ordering, PartialOrd};
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone, Eq, Ord)]
|
||||||
pub enum Token {
|
pub enum Token {
|
||||||
Integer(u64),
|
Integer(u64),
|
||||||
List(Vec<Token>),
|
List(Vec<Token>),
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
// Copyright 2022 Christian Ulrich
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
// usage: ./part1 < input
|
||||||
|
|
||||||
|
pub mod common;
|
||||||
|
|
||||||
|
use common::Token;
|
||||||
|
|
||||||
|
fn main() -> Result<(), &'static str> {
|
||||||
|
let mut packets = Vec::new();
|
||||||
|
for pair in common::packet_pairs() {
|
||||||
|
let (left, right) = pair?;
|
||||||
|
packets.push(left);
|
||||||
|
packets.push(right);
|
||||||
|
}
|
||||||
|
let divider1 = Token::from_str("[[2]]")?;
|
||||||
|
let divider2 = Token::from_str("[[6]]")?;
|
||||||
|
packets.push(divider1.clone());
|
||||||
|
packets.push(divider2.clone());
|
||||||
|
packets.sort();
|
||||||
|
let divider1_pos = packets.iter().position(|p| p == ÷r1).unwrap() + 1;
|
||||||
|
let divider2_pos = packets.iter().position(|p| p == ÷r2).unwrap() + 1;
|
||||||
|
println!("{}", divider1_pos * divider2_pos);
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
Reference in New Issue