aboutsummaryrefslogtreecommitdiff
path: root/2022/15/a.rs
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-07-02 14:45:11 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-07-02 14:45:11 +0200
commit6b89133a79e798edadca7eb59800441535e97670 (patch)
tree2ee1b25378fa235038f7ce28b5b7896c64bda259 /2022/15/a.rs
parentd287854b301bb8b4726b50ac21513b658fe1fb6b (diff)
downloadaoc-6b89133a79e798edadca7eb59800441535e97670.tar.gz
aoc-6b89133a79e798edadca7eb59800441535e97670.zip
Day 15 2022
Diffstat (limited to '2022/15/a.rs')
-rw-r--r--2022/15/a.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/2022/15/a.rs b/2022/15/a.rs
new file mode 100644
index 0000000..7b87150
--- /dev/null
+++ b/2022/15/a.rs
@@ -0,0 +1,30 @@
1use std::cmp::max;
2use std::collections::HashSet;
3mod common;
4use common::*;
5
6fn main() {
7 const Y: i64 = 2000000;
8 let sensors = read_sensors_from_stdin();
9 let mut ranges = sensors.iter()
10 .map(|s| s.get_range(Y))
11 .filter(|r| r.left <= r.right)
12 .collect::<Vec<_>>();
13 ranges.sort();
14 let mut current = Range { left: i64::MIN, right: i64::MIN };
15 let mut sum = 0;
16 for r in ranges {
17 current = Range {
18 left: max(current.right+1, r.left),
19 right: max(current.right, r.right)
20 };
21 sum += (current.right - current.left + 1) as usize;
22 }
23 sum -= sensors.iter()
24 .map(|s| s.b)
25 .collect::<HashSet<_>>() // Remove duplicates
26 .iter()
27 .filter(|b| b.y == Y)
28 .count();
29 println!("{sum}");
30}

Generated with cgit - Back to sebastiano.tronto.net