2022 day 23 parsing

This commit is contained in:
Maciej Jur 2022-12-23 17:12:57 +01:00
parent abb34e8d23
commit 03c7d0a04c
3 changed files with 64 additions and 1 deletions

View file

@ -24,5 +24,6 @@ fn main() {
// solutions::day19::run();
// solutions::day20::run();
// solutions::day21::run();
solutions::day22::run();
// solutions::day22::run();
solutions::day23::run();
}

View file

@ -0,0 +1,61 @@
use std::collections::HashSet;
use crate::utils;
pub fn run() -> () {
let data = parse_data(&utils::read_lines(utils::Source::Day(23)));
println!("Day 23");
println!("Part 1: {}", solve1(&data));
println!("Part 2: {}", solve2(&data));
}
type Location = (isize, isize);
fn solve1(data: &HashSet<Location>) -> i32 {
println!("{:?}", data);
1
}
fn solve2(data: &HashSet<Location>) -> i32 {
2
}
fn parse_data<T: AsRef<str>>(data: &[T]) -> HashSet<Location> {
data.iter()
.enumerate()
.flat_map(|(row, line)| line.as_ref()
.char_indices()
.filter(|&(_, c)| c == '#')
.map(move |(col, _)| (row as isize, col as isize))
)
.collect()
}
#[cfg(test)]
mod tests {
use super::*;
static DATA: &[&str] = &[
".....",
"..##.",
"..#..",
".....",
"..##.",
".....",
];
#[test]
fn part1() {
assert_eq!(1, solve1(&parse_data(DATA)));
}
#[test]
fn part2() {
assert_eq!(2, solve2(&parse_data(DATA)));
}
}

View file

@ -20,3 +20,4 @@ pub mod day19;
pub mod day20;
pub mod day21;
pub mod day22;
pub mod day23;