From 67515a357519a3c2fac699ba2e8c56e671b651c5 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 25 Dec 2022 00:37:06 -0500 Subject: day 25 --- benches/2022.rs | 5 +++ data/2022/25.txt | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/bin/2022/day25.rs | 63 +++++++++++++++++++++++++++ src/bin/2022/main.rs | 2 + 4 files changed, 186 insertions(+) create mode 100644 data/2022/25.txt create mode 100644 src/bin/2022/day25.rs diff --git a/benches/2022.rs b/benches/2022.rs index 6b7363d..4d2f322 100644 --- a/benches/2022.rs +++ b/benches/2022.rs @@ -47,6 +47,8 @@ mod day21; mod day23; #[path = "../src/bin/2022/day24.rs"] mod day24; +#[path = "../src/bin/2022/day25.rs"] +mod day25; // NEXT MOD day!(2022, 1, day1); @@ -72,6 +74,7 @@ day!(2022, 20, day20); day!(2022, 21, day21); day!(2022, 23, day23); day!(2022, 24, day24); +day!(2022, 25, day25); // NEXT DAY fn bench_2022(c: &mut criterion::Criterion) { @@ -100,6 +103,7 @@ fn bench_2022(c: &mut criterion::Criterion) { day_combined!(2022, 21, day21); day_combined!(2022, 23, day23); day_combined!(2022, 24, day24); + day_combined!(2022, 25, day25); // NEXT DAY COMBINED }) }); @@ -131,5 +135,6 @@ criterion::criterion_main!( bench_2022day21, bench_2022day23, bench_2022day24, + bench_2022day25, // NEXT GROUP ); diff --git a/data/2022/25.txt b/data/2022/25.txt new file mode 100644 index 0000000..bc619f6 --- /dev/null +++ b/data/2022/25.txt @@ -0,0 +1,116 @@ +1=-=2=-1000=0 +11=001122 +120- +1-0 +202-0==-2- +2-1010=2-2=01 +112=-2 +2-0= +1-=2-=-1-0--0=1=0000 +1=0=0--021-0 +11000101=210 +21-111=2112=2==- +111010-2 +2=10=-101-=--0 +2-=-2000012=0022= +1-=11-01--2100 +1=2211-2-=== +2=--2-==-1 +1=12---02=2 +1==0=--11=01-1- +121-21021 +12=1001=2=-=22 +1=2-212=2-0211 +20----11= +10=100=0=0 +111 +1=--011==2--212121= +2=-10=210200-2-=0 +1=-122=001-1 +2-0=0121=-0=0 +2-=20--1-=21-22=1= +20011 +12=1--=-0--10-0=1-= +2002=100=-00- +202 +1=2==21- +1=221--01=00-10= +1--0-1= +2-==11=222--- +21-10-=22 +1=--22-0- +2-0- +1-0=-2 +20-02102 +1=0=20----21=12=- +20=111-12=21101= +111=1=-2=0=--21 +11- +10-1=01=- +1222-10 +1=2-1 +20 +101==12-1-0 +1-=22=--=22=1=22 +1200-010-10=021 +1=2-10=-02--=- +12-0=000=0 +1==10=00===1-- +2-1=-=1===1=-0=--- +1=11=120 +2===002010=-=0 +1==00212=01-002=221 +10020221===- +1--01=-=0-20-101-=- +112=101 +10- +1220=1 +2= +1=1120=--0 +11-21200= +2==011-10-0==0=0= +12-=102 +100-022 +1=1 +201-0--=- +2-02 +21=11=00020 +12=20- +1101=00-1 +1=0=-11--=-010-==1 +1-2-0=00=-=220=11- +2-2 +12-2 +12=10=2-= +20222110-10002 +1002=0 +12=11-=012 +1== +1=00-01 +110101222-020--111 +2-0 +1-12=1 +222-10-12=00 +11=1=1 +10=2-00-121-2-=2 +1---22-1-0=00-1220 +2-=2210=-==2=010= +12201-111-220 +2=122=022=22=12-1 +211===2=020 +121-2-0-=0==2=1 +1-0221200-21100- +10 +1-11 +2===2=-2- +1-0-2021-21== +1==-00-=2-21===1200 +22 +1222=20=120=1- +11=120001012==01-1 +2=-1--00 +10==121--221 +1=2100102=20012 +2==1- +1- +10-2--0 diff --git a/src/bin/2022/day25.rs b/src/bin/2022/day25.rs new file mode 100644 index 0000000..3149365 --- /dev/null +++ b/src/bin/2022/day25.rs @@ -0,0 +1,63 @@ +#![allow(dead_code)] +#![allow(unused_variables)] + +use advent_of_code::prelude::*; + +fn from_snafu(line: String) -> i64 { + let mut total = 0; + for c in line.chars() { + let digit = match c { + '2' => 2, + '1' => 1, + '0' => 0, + '-' => -1, + '=' => -2, + _ => panic!("unknown char {}", c), + }; + total *= 5; + total += digit; + } + total +} + +fn to_snafu(mut n: i64) -> String { + let mut s = String::new(); + while n > 0 { + let rem = n % 5; + let c = match rem { + 0 => '0', + 1 => '1', + 2 => '2', + 3 => '=', + 4 => '-', + _ => unreachable!(), + }; + s.insert(0, c); + n = (n + 2) / 5; + } + s +} + +pub fn parse(fh: File) -> Result> { + Ok(parse::raw_lines(fh)) +} + +pub fn part1(lines: impl Iterator) -> Result { + Ok(to_snafu(lines.map(from_snafu).sum())) +} + +pub fn part2(_: impl Iterator) -> Result { + todo!() +} + +#[test] +fn test() { + assert_eq!( + part1(parse(parse::data(2022, 25).unwrap()).unwrap()).unwrap(), + "2-20=01--0=0=0=2-120" + ); + // assert_eq!( + // part2(parse(parse::data(2022, 25).unwrap()).unwrap()).unwrap(), + // 0 + // ); +} diff --git a/src/bin/2022/main.rs b/src/bin/2022/main.rs index 10b06fe..46cc3bb 100644 --- a/src/bin/2022/main.rs +++ b/src/bin/2022/main.rs @@ -34,6 +34,7 @@ mod day20; mod day21; mod day23; mod day24; +mod day25; // NEXT MOD #[paw::main] @@ -63,6 +64,7 @@ fn main(opt: Opt) -> Result<()> { 21 => advent_of_code::day!(2022, opt.day, opt.puzzle, day21), 23 => advent_of_code::day!(2022, opt.day, opt.puzzle, day23), 24 => advent_of_code::day!(2022, opt.day, opt.puzzle, day24), + 25 => advent_of_code::day!(2022, opt.day, opt.puzzle, day25), // NEXT PART _ => panic!("unknown day {}", opt.day), } -- cgit v1.2.3-54-g00ecf