aboutsummaryrefslogtreecommitdiff
path: root/2022/14/b.rs
diff options
context:
space:
mode:
Diffstat (limited to '2022/14/b.rs')
-rw-r--r--2022/14/b.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/2022/14/b.rs b/2022/14/b.rs
new file mode 100644
index 0000000..f8a4829
--- /dev/null
+++ b/2022/14/b.rs
@@ -0,0 +1,22 @@
1mod common;
2use common::*;
3
4fn drop(map: &mut Map, i: (usize, usize)) -> bool {
5 let (x, y) = i;
6 if y < map.ymax {
7 for j in vec![(x, y+1), (x-1, y+1), (x+1, y+1)].into_iter() {
8 if !map.at(j) { return drop(map, j); }
9 }
10 }
11
12 map[i] = true;
13 !map.at((500, 0)) // Returns false after filling the last -> off by 1
14}
15
16fn main() {
17 let mut map = read_map_from_stdin();
18 let mut i = 0;
19 while drop(&mut map, (500, 0)) { i += 1; }
20 //map.print();
21 println!("{}", i+1);
22}

Generated with cgit - Back to sebastiano.tronto.net