summaryrefslogtreecommitdiff
path: root/2024/04/rust/src/main.rs
blob: f3b152c3b21e5426aa5655ce1addc1a9e4ef116a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#![feature(iter_order_by)]

use aoc::grid::{chebyshev_ball, Grid};
use std::io;

fn main() -> io::Result<()> {
    let grid: Vec<Vec<char>> = io::stdin()
        .lines()
        .map(|line| line.unwrap().chars().collect())
        .collect();
    let grid = Grid::new(grid);

    let silver: usize = silver(&grid);
    let gold: u64 = 0;
    println!("silver: {silver}");
    println!("gold: {gold}");

    return Ok(());
}

fn silver(grid: &Grid<char>) -> usize {
    grid.points()
        .flat_map(|p| chebyshev_ball(1).map(move |dp| grid.ray(p, dp)))
        .map(|cs| cs.take(4).eq_by("XMAS".chars(), |a, b| *a == b))
        .filter(|p| *p)
        .count()
}