From bce2009698f7ef4ba066ee5122500fe32c1289cd Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Wed, 2 Jul 2025 11:21:58 +0200 Subject: Day 14 2022 --- 2022/14/a.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 2022/14/a.rs (limited to '2022/14/a.rs') diff --git a/2022/14/a.rs b/2022/14/a.rs new file mode 100644 index 0000000..e775c23 --- /dev/null +++ b/2022/14/a.rs @@ -0,0 +1,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}"); +} -- cgit v1.3