Skip to content

Commit

Permalink
just pushing local changes so can work on elsewhere
Browse files Browse the repository at this point in the history
  • Loading branch information
jhrcook committed Jan 10, 2024
1 parent 7b3663a commit f85316c
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 7 deletions.
58 changes: 58 additions & 0 deletions puzzle-input/20.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
%pj -> sh
%mn -> jp
&hf -> rg, vl, tq, qq, mv, zz
%xl -> hf
%sv -> mn, dl
%kk -> lh
&sj -> kz
%jj -> lq, kk
%mr -> bm, hb
%sx -> lq, fn
%fn -> zr, lq
%pf -> dl, gv
%lr -> jj, lq
%jp -> dl, pj
&hb -> sj, mr, rz, qg, pr
%vg -> zz, hf
%pr -> zq
%hn -> pf
%jg -> tj
%qg -> vk
%dv -> xl, hf
&qq -> kz
%fm -> lr
&ls -> kz
%pd -> hb, xg
%rj -> hb
%fb -> hf, tq
%zz -> np
%bm -> pd, hb
%xn -> lq, fm
%gv -> jg, dl
%dz -> sx
%zs -> dl, nh
%tj -> zs, dl
%mv -> vl
&kz -> rx
%np -> cl, hf
&bg -> kz
%vl -> vg
%xg -> rz, hb
%rz -> pr
%zq -> hb, qg
%lh -> rd
%zr -> lq
%fl -> hb, rj
%xr -> xn, lq
%rd -> dz, lq
%cl -> hf, gj
%nh -> dl
%sh -> hn, dl
%vk -> fx, hb
%gj -> hf, dv
%tq -> mv
&dl -> hn, pj, ls, mn, jg, sv
%fx -> fl, hb
&lq -> bg, kk, dz, xr, lh, fm
%rg -> hf, fb
broadcaster -> xr, mr, rg, sv
21 changes: 15 additions & 6 deletions src/solutions/day19.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,15 @@ pub fn puzzle_1(input: &str) -> Result<u32, PuzzleErr> {
Ok(organize_parts(&parts, &workflows_map))
}

pub fn puzzle_2(input: &str) -> Result<u32, PuzzleErr> {
let (workflows, parts) = parse_input(input)?;
let workflows_map = workflows
.iter()
.map(|w| (w.name.as_str(), w.clone()))
.collect::<HashMap<&str, Workflow>>();
Ok(organize_parts(&parts, &workflows_map))
}

pub fn main(data_dir: &str) {
println!("Day 19: Aplenty");
let data = load(data_dir, 19, None);
Expand All @@ -269,13 +278,13 @@ pub fn main(data_dir: &str) {
Ok(x) => println!(" Puzzle 1: {}", x),
Err(e) => panic!("No solution to puzzle 1: {}.", e),
}
// assert_eq!(answer_1, Ok(37113));
assert_eq!(answer_1, Ok(509597));

// Puzzle 2.
// let answer_2 = puzzle_2(&data);
// match answer_2 {
// Ok(x) => println!(" Puzzle 2: {}", x),
// Err(e) => panic!("No solution to puzzle 2: {}", e),
// }
let answer_2 = puzzle_2(&data);
match answer_2 {
Ok(x) => println!(" Puzzle 2: {}", x),
Err(e) => panic!("No solution to puzzle 2: {}", e),
}
// assert_eq!(answer_2, Ok(30449))
}
8 changes: 7 additions & 1 deletion tests/test_day19.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use aoc_2023::solutions::day19::puzzle_1;
use aoc_2023::solutions::day19::{puzzle_1, puzzle_2};

const EXAMPLE_INPUT_1: &str = "
px{a<2006:qkq,m>2090:A,rfg}
Expand All @@ -25,3 +25,9 @@ fn puzzle_1_example_1() {
let _ = env_logger::try_init();
assert_eq!(puzzle_1(self::EXAMPLE_INPUT_1), Ok(19114));
}

#[test]
fn puzzle_2_example_1() {
let _ = env_logger::try_init();
assert_eq!(puzzle_1(self::EXAMPLE_INPUT_1), Ok(167409079868000));
}

0 comments on commit f85316c

Please sign in to comment.