Skip to content

Commit 7ca3784

Browse files
2024: Day 25
Part 1: 00:12:42 / Rank 1150 Part 2: 00:12:49 / Rank 959
1 parent 98b2efe commit 7ca3784

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

2024/day25/.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"[rust]": {
3+
"editor.defaultFormatter": "rust-lang.rust-analyzer",
4+
"editor.formatOnSave": true
5+
},
6+
"rust-analyzer.check.command": "clippy"
7+
}

2024/day25/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

2024/day25/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[package]
2+
name = "day25"
3+
version = "0.1.0"
4+
edition = "2021"

2024/day25/src/main.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
use std::fs;
2+
3+
fn main() {
4+
let input = fs::read_to_string("input.txt").expect("Could not read file");
5+
6+
let grids = input.split("\n\n").collect::<Vec<_>>();
7+
8+
let mut locks = Vec::new();
9+
let mut keys = Vec::new();
10+
11+
// decide which grids are locks and which are keys and calculate pin heights
12+
let mut total_height = 0;
13+
for g in grids.iter() {
14+
let g = g
15+
.lines()
16+
.map(|l| l.chars().collect::<Vec<_>>())
17+
.collect::<Vec<_>>();
18+
let is_key = g[0][0] != '#';
19+
total_height = g.len();
20+
21+
let mut heights = vec![0usize; g[0].len()];
22+
for row in g {
23+
for (x, c) in row.iter().enumerate() {
24+
if *c == '#' {
25+
heights[x] += 1;
26+
}
27+
}
28+
}
29+
30+
if is_key {
31+
keys.push(heights);
32+
} else {
33+
locks.push(heights);
34+
}
35+
}
36+
37+
// check which key fits into which lock
38+
let mut total = 0;
39+
for k in &keys {
40+
for l in &locks {
41+
if k.iter().zip(l).all(|(a, b)| a + b <= total_height) {
42+
total += 1;
43+
}
44+
}
45+
}
46+
47+
println!("{}", total);
48+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy