From ef55813034298979423833ee5e77161b19f100ce Mon Sep 17 00:00:00 2001 From: Avril Date: Fri, 11 Dec 2020 22:46:40 +0000 Subject: [PATCH] fix broken gitignore --- .gitignore | 3 ++ day10/src/input.rs | 80 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 day10/src/input.rs diff --git a/.gitignore b/.gitignore index 37efd27..1313560 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ target/ *.o *.gcda + +# Specific days +!day10/src/input.rs diff --git a/day10/src/input.rs b/day10/src/input.rs new file mode 100644 index 0000000..1fb82ae --- /dev/null +++ b/day10/src/input.rs @@ -0,0 +1,80 @@ +use std::{ + io::{ + BufRead, + }, +}; + +pub fn test(input: impl IntoIterator) +{ + for x in input + { + if !(0..=255).contains(&x) { + panic!("Overflew u8: {}", x); + } else { + println!(" -> {} OK", x); + } + } +} + + +pub type Int = u8; + +/// Read the real input from a file +pub fn read_input<'r, R: BufRead+ 'r>(from: R) -> impl Iterator + 'r +{ + from.lines().filter_map(|x| x.ok().map(|y| y.parse().ok()).flatten()) +} + +/// Get the test input +pub fn test_input() -> impl Iterator +{ + return TEST_INPUT_2.iter().copied() +} + +const TEST_INPUT: &[Int] = &[ + 16, + 10, + 15, + 5, + 1, + 11, + 7, + 19, + 6, + 12, + 4, +]; + +const TEST_INPUT_2: &[Int] = &[ + 28, + 33, + 18, + 42, + 31, + 14, + 46, + 20, + 48, + 47, + 24, + 23, + 49, + 45, + 19, + 38, + 39, + 11, + 1, + 32, + 25, + 35, + 8, + 17, + 7, + 9, + 4, + 2, + 34, + 10, + 3, +];