diff --git a/2022/src/bin/day08.rs b/2022/src/bin/day08.rs index 0b82eae..e6b5f2b 100644 --- a/2022/src/bin/day08.rs +++ b/2022/src/bin/day08.rs @@ -40,7 +40,7 @@ impl Visibility { impl Grid { fn new(text: &str) -> Self { let mut map = HashMap::new(); - let lines = aoc::split_lines(text); + let lines: Vec<&str> = aoc::lines(text).collect(); let rows = lines.len(); let cols = lines[0].len(); diff --git a/2022/src/bin/day09.rs b/2022/src/bin/day09.rs index 9e8c21f..5c115c6 100644 --- a/2022/src/bin/day09.rs +++ b/2022/src/bin/day09.rs @@ -43,10 +43,9 @@ struct Step { } fn parse_input(input: &str) -> Vec { - aoc::split_lines(input) - .iter() + aoc::lines(input) .map(|line| { - let words = aoc::split_words(line); + let words: Vec<&str> = aoc::words(line).collect(); let d = Direction::from_str(words[0]).unwrap(); let n = words[1].parse::().unwrap(); diff --git a/2022/src/bin/day10.rs b/2022/src/bin/day10.rs index 3d7c108..4951cf5 100644 --- a/2022/src/bin/day10.rs +++ b/2022/src/bin/day10.rs @@ -20,10 +20,9 @@ enum Instruction { } fn parse(input: &str) -> Vec { - aoc::split_lines(input) - .iter() + aoc::lines(input) .map(|line| { - let w = aoc::split_words(line); + let w: Vec<&str> = aoc::words(line).collect(); match w[0] { "noop" => Instruction::Noop, "addx" => Instruction::Addx(w[1].parse().unwrap()), diff --git a/2022/src/lib.rs b/2022/src/lib.rs index fca4069..9177771 100644 --- a/2022/src/lib.rs +++ b/2022/src/lib.rs @@ -1,7 +1,13 @@ -pub fn split_lines(s: &str) -> Vec<&str> { - s.trim_end().split('\n').collect() +use std::str::Split; + +pub fn lines(s: &str) -> Split { + s.trim_end().split('\n') } -pub fn split_words(s: &str) -> Vec<&str> { - s.split(' ').collect() +pub fn words(s: &str) -> Split { + s.split(' ') +} + +pub fn blocks(s: &str) -> Split<&str> { + s.split("\n\n") }