From be0bfd0545231b718db3a74a169035b8d47be95e Mon Sep 17 00:00:00 2001 From: George Thomas Date: Mon, 12 Jan 2026 22:27:41 +0000 Subject: [PATCH] Pass `is_real_data` to parsers As in Haskell, we'll need this for some awkward problems. --- rust/main.rs | 8 ++++---- rust/puzzle.rs | 2 +- rust/puzzles/day1.rs | 2 +- rust/puzzles/day2.rs | 2 +- rust/puzzles/day3.rs | 2 +- rust/puzzles/day4.rs | 2 +- rust/puzzles/day5.rs | 2 +- rust/puzzles/day6.rs | 2 +- rust/puzzles/day7.rs | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/rust/main.rs b/rust/main.rs index bedc365..b0014d2 100644 --- a/rust/main.rs +++ b/rust/main.rs @@ -29,7 +29,7 @@ fn main() { println!(" {}", puzzle.number()); let input = fs::read_to_string(format!("../inputs/{}/{}", t, puzzle.number())) .expect("no input file"); - puzzle.with_parts(&input, &|n, run| { + puzzle.with_parts(*is_real_data, &input, &|n, run| { let expected = fs::read_to_string(format!("../outputs/{}/{}/{}", t, puzzle.number(), n)) .expect("no golden file"); @@ -53,14 +53,14 @@ fn main() { pub trait SomePuzzle { fn number(&self) -> u32; - fn with_parts(&self, input: &str, f: &dyn Fn(usize, &dyn Fn() -> String)); + fn with_parts(&self, is_real_data: bool, input: &str, f: &dyn Fn(usize, &dyn Fn() -> String)); } impl SomePuzzle for Puzzle { fn number(&self) -> u32 { self.number } - fn with_parts(&self, s: &str, f: &dyn Fn(usize, &dyn Fn() -> String)) { - let input = (self.parser)(s); + fn with_parts(&self, is_real_data: bool, s: &str, f: &dyn Fn(usize, &dyn Fn() -> String)) { + let input = (self.parser)(is_real_data, s); for (i, p) in self.parts.iter().enumerate() { f(i + 1, &|| p(&input)); } diff --git a/rust/puzzle.rs b/rust/puzzle.rs index 8f01d12..391a7a9 100644 --- a/rust/puzzle.rs +++ b/rust/puzzle.rs @@ -1,5 +1,5 @@ pub struct Puzzle { pub number: u32, - pub parser: fn(&str) -> Input, + pub parser: fn(bool, &str) -> Input, pub parts: [fn(&Input) -> String; N], } diff --git a/rust/puzzles/day1.rs b/rust/puzzles/day1.rs index 510a107..2ffc442 100644 --- a/rust/puzzles/day1.rs +++ b/rust/puzzles/day1.rs @@ -11,7 +11,7 @@ use nom::{ pub const PUZZLE: Puzzle, 2> = Puzzle { number: 1, - parser: |input| { + parser: |_, input| { terminated::<_, _, Error<&str>, _, _>( terminated( separated_list1( diff --git a/rust/puzzles/day2.rs b/rust/puzzles/day2.rs index 1171c55..9c0365c 100644 --- a/rust/puzzles/day2.rs +++ b/rust/puzzles/day2.rs @@ -10,7 +10,7 @@ use nom::{ pub const PUZZLE: Puzzle, 2> = Puzzle { number: 2, - parser: |input| { + parser: |_, input| { terminated::<_, _, Error<&str>, _, _>( terminated( separated_list1(char(','), separated_pair(usize, char('-'), usize)), diff --git a/rust/puzzles/day3.rs b/rust/puzzles/day3.rs index ceb7e7f..1b85782 100644 --- a/rust/puzzles/day3.rs +++ b/rust/puzzles/day3.rs @@ -10,7 +10,7 @@ use nom::{ pub const PUZZLE: Puzzle>, 2> = Puzzle { number: 3, - parser: |input| { + parser: |_, input| { terminated::<_, _, Error<&str>, _, _>( terminated( separated_list1( diff --git a/rust/puzzles/day4.rs b/rust/puzzles/day4.rs index 91fbe1d..6779d1f 100644 --- a/rust/puzzles/day4.rs +++ b/rust/puzzles/day4.rs @@ -11,7 +11,7 @@ use nom::{ pub const PUZZLE: Puzzle>, 2> = Puzzle { number: 4, - parser: |input| { + parser: |_, input| { terminated::<_, _, Error<&str>, _, _>( terminated( separated_list1( diff --git a/rust/puzzles/day5.rs b/rust/puzzles/day5.rs index 92ad227..4b74cdd 100644 --- a/rust/puzzles/day5.rs +++ b/rust/puzzles/day5.rs @@ -11,7 +11,7 @@ use nom::{ pub const PUZZLE: Puzzle<(Vec, Vec), 2> = Puzzle { number: 5, - parser: |input| { + parser: |_, input| { terminated::<_, _, Error<&str>, _, _>( separated_pair( separated_list1( diff --git a/rust/puzzles/day6.rs b/rust/puzzles/day6.rs index e7643df..3207dee 100644 --- a/rust/puzzles/day6.rs +++ b/rust/puzzles/day6.rs @@ -13,7 +13,7 @@ use std::ops::{Add, Mul}; pub const PUZZLE: Puzzle<(Vec, Vec>>), 2> = Puzzle { number: 6, - parser: |input| { + parser: |_, input| { terminated::<_, _, Error<&str>, _, _>( ( terminated( diff --git a/rust/puzzles/day7.rs b/rust/puzzles/day7.rs index 120f231..036921a 100644 --- a/rust/puzzles/day7.rs +++ b/rust/puzzles/day7.rs @@ -13,7 +13,7 @@ use std::collections::{HashMap, HashSet}; pub const PUZZLE: Puzzle<(usize, Vec>), 2> = Puzzle { number: 7, - parser: |input| { + parser: |_, input| { terminated::<_, _, Error<&str>, _, _>( terminated( (