use std::time::Instant; use marble_machinations::{level::Level, marble_engine::Machine, solution::Solution}; fn main() { aoc_2024_1a(); } fn aoc_2024_1a() { println!("running aoc_2024_1a"); benchmark( include_str!("../benchmarks/aoc_2024_1a_level.json"), include_str!("../benchmarks/aoc_2024_1a_solution.json"), ); } fn benchmark(level: &str, solution: &str) { let level: Level = serde_json::from_str(level).unwrap(); let solution: Solution = serde_json::from_str(solution).unwrap(); let cycle_count = solution.score.unwrap().cycles; let mut machine = Machine::new_empty(); machine.set_grid(solution.board.grid); let start_time = Instant::now(); for (n, stage) in level.stages().iter().enumerate() { machine.set_input(stage.input().as_bytes().to_owned()); for _ in 0..cycle_count { machine.step(); } assert_eq!(machine.output(), stage.output().as_bytes()); println!("passed stage {n}"); machine.reset(); } let elapsed = start_time.elapsed(); println!("took {elapsed:?}"); }