#advent #solution #input #parser #line #aoc #aocli

aoclib

Runner for Advent of Code solutions with aocli

3 unstable releases

0.2.1 Jul 15, 2023
0.2.0 Jul 15, 2023
0.1.0 Jun 20, 2023

#29 in #aoc

MIT license

35KB
411 lines

aoclib

A library for running Advent of Code solutions using aocli, and for parsing Advent of Code inputs.

Examples

use aoc::Parse;

let line_1 = "first: 85, then: +192, finally: -64";
let line_2 = "first: -157, then: 4, finally: 1000";

fn parse_line(line: &str) -> [i32; 3] {
    let mut parser = line.as_parser();
    [
        parser.between("first: ", ", "),
        parser.between("then: ", ", "),
        parser.after("finally: "),
    ]
    .map(Parse::parse_uw)
}

assert_eq!(line_1.ints::<3, i32>(), [85, 192, -64]);
assert_eq!(parse_line(line_1), [85, 192, -64]);

assert_eq!(line_2.ints::<3, i32>(), [-157, 4, 1000]);
assert_eq!(parse_line(line_2), [-157, 4, 1000]);

lib.rs:

A library for running Advent of Code solutions using aocli, and for parsing Advent of Code inputs.

Examples

use aoc::Parse;

let line_1 = "first: 85, then: +192, finally: -64";
let line_2 = "first: -157, then: 4, finally: 1000";

fn parse_line(line: &str) -> [i32; 3] {
    let mut parser = line.as_parser();
    [
        parser.between("first: ", ", "),
        parser.between("then: ", ", "),
        parser.after("finally: "),
    ]
    .map(Parse::parse_uw)
}

assert_eq!(line_1.ints::<3, i32>(), [85, 192, -64]);
assert_eq!(parse_line(line_1), [85, 192, -64]);

assert_eq!(line_2.ints::<3, i32>(), [-157, 4, 1000]);
assert_eq!(parse_line(line_2), [-157, 4, 1000]);

No runtime deps