aboutsummaryrefslogtreecommitdiff
path: root/2022/14/a.rs
blob: e775c235e3287ab1d77e62bb2c58e0a5613bca4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
mod common;
use common::*;

fn drop(map: &mut Map, i: (usize, usize)) -> bool {
    let (x, y) = i;
    if y > map.ymax { return false; }

    for j in vec![(x, y+1), (x-1, y+1), (x+1, y+1)].into_iter() {
        if !map.at(j) { return drop(map, j); }
    }

    map[i] = true;
    true
}

fn main() {
    let mut map = read_map_from_stdin();
    let mut i = 0;
    while drop(&mut map, (500, 0)) { i+= 1; }
    //map.print();
    println!("{i}");
}

Generated with cgit - Back to sebastiano.tronto.net