summaryrefslogtreecommitdiff
path: root/2024/04/rust/src/main.rs
diff options
context:
space:
mode:
authormhsn <mail@mhsn.net>2025-06-03 13:58:21 +0000
committermhsn <mail@mhsn.net>2025-06-03 13:58:21 +0000
commitd9088a9fbfda5bcaddaf41bf7be4cd2298eb7a07 (patch)
treeef278f23353c77142d980c816bd0903bb03e5f29 /2024/04/rust/src/main.rs
parent276044e1b6080790e582c82d1b48591b715488b5 (diff)
downloadaoc-master.tar.gz
aoc-master.zip
reorg rust libHEADmaster
Diffstat (limited to '2024/04/rust/src/main.rs')
-rw-r--r--2024/04/rust/src/main.rs18
1 files changed, 5 insertions, 13 deletions
diff --git a/2024/04/rust/src/main.rs b/2024/04/rust/src/main.rs
index fd6a715..f3b152c 100644
--- a/2024/04/rust/src/main.rs
+++ b/2024/04/rust/src/main.rs
@@ -1,4 +1,6 @@
-use aoc::Grid;
+#![feature(iter_order_by)]
+
+use aoc::grid::{chebyshev_ball, Grid};
use std::io;
fn main() -> io::Result<()> {
@@ -17,19 +19,9 @@ fn main() -> io::Result<()> {
}
fn silver(grid: &Grid<char>) -> usize {
- let dirs = [
- (1, 1),
- (1, 0),
- (1, -1),
- (0, 1),
- (0, -1),
- (-1, 1),
- (-1, 0),
- (-1, -1),
- ];
grid.points()
- .flat_map(|p| dirs.into_iter().map(move |dp| grid.ray(p, dp)))
- .map(|cs| cs.zip("XMAS".chars()).all(|(&a, b)| a == b))
+ .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()
}