20 lines
566 B
Rust
20 lines
566 B
Rust
use itertools::Itertools;
|
|
use std::{fs, io};
|
|
|
|
fn format_path(day_num: usize, file: &str) -> String {
|
|
format!("data/day{day_num:02}/{file}")
|
|
}
|
|
|
|
pub fn read_string(day_num: usize, file: &str) -> io::Result<String> {
|
|
Ok(fs::read_to_string(format_path(day_num, file))?)
|
|
}
|
|
|
|
pub fn split_lines<'a>(lines: &'a str) -> impl Iterator<Item = &'a str> + 'a {
|
|
lines
|
|
.split('\n')
|
|
.with_position()
|
|
.filter_map(|(pos, line)| match pos {
|
|
itertools::Position::Last if line.is_empty() => None,
|
|
_ => Some(line),
|
|
})
|
|
}
|