diff --git a/rust/puzzles/day1.rs b/rust/puzzles/day1.rs index 2d00a62..510a107 100644 --- a/rust/puzzles/day1.rs +++ b/rust/puzzles/day1.rs @@ -2,8 +2,8 @@ use crate::puzzle::Puzzle; use nom::{ Parser, branch::alt, - character::complete::{char, digit1, newline}, - combinator::{eof, map_res, value}, + character::complete::{char, i32, newline}, + combinator::{eof, value}, error::Error, multi::separated_list1, sequence::{pair, terminated}, @@ -12,7 +12,7 @@ use nom::{ pub const PUZZLE: Puzzle, 2> = Puzzle { number: 1, parser: |input| { - terminated( + terminated::<_, _, Error<&str>, _, _>( terminated( separated_list1( newline, @@ -21,7 +21,7 @@ pub const PUZZLE: Puzzle, 2> = Puzzle { value(Direction::L, char('L')), value(Direction::R, char('R')), )), - parse_int(), + i32, ), ), newline, @@ -83,7 +83,3 @@ fn step(i: i32, d: Direction, p: i32) -> (i32, i32) { }; (p1.div_euclid(100), p1.rem_euclid(100)) } - -fn parse_int<'a>() -> impl Parser<&'a str, Output = i32, Error = Error<&'a str>> { - map_res(digit1, |s: &str| s.parse::()) -} diff --git a/rust/puzzles/day2.rs b/rust/puzzles/day2.rs index bc9063d..1171c55 100644 --- a/rust/puzzles/day2.rs +++ b/rust/puzzles/day2.rs @@ -1,8 +1,8 @@ use crate::puzzle::Puzzle; use nom::{ Parser, - character::complete::{char, digit1, newline}, - combinator::{eof, map_res}, + character::complete::{char, newline, usize}, + combinator::eof, error::Error, multi::separated_list1, sequence::{separated_pair, terminated}, @@ -11,12 +11,9 @@ use nom::{ pub const PUZZLE: Puzzle, 2> = Puzzle { number: 2, parser: |input| { - terminated( + terminated::<_, _, Error<&str>, _, _>( terminated( - separated_list1( - char(','), - separated_pair(parse_int(), char('-'), parse_int()), - ), + separated_list1(char(','), separated_pair(usize, char('-'), usize)), newline, ), eof, @@ -70,7 +67,3 @@ fn equal_chunks(n: &String, i: usize) -> bool { Some(x) => chunks.all(|y| y == x), } } - -fn parse_int<'a>() -> impl Parser<&'a str, Output = usize, Error = Error<&'a str>> { - map_res(digit1, |s: &str| s.parse::()) -}