tangled
alpha
login
or
join now
cherry.computer
/
aoc25
My submissions for Advent of Code 2025
adventofcode.com/2025
rust
aoc
0
fork
atom
overview
issues
pulls
pipelines
add solution for day 8 part 1
cherry.computer
1 month ago
dc362e27
ca414a2c
verified
This commit was signed with the committer's
known signature
.
cherry.computer
SSH Key Fingerprint:
SHA256:SIA77Ll0IpMb8Xd3RtaGT+PBIGIePhJJg5W2r6Td7cc=
+63
3 changed files
expand all
collapse all
unified
split
08
part1
Cargo.toml
src
main.rs
Cargo.lock
+4
08/part1/Cargo.toml
···
0
0
0
0
···
1
+
[package]
2
+
name = "aoc25-08-1"
3
+
version = "1.0.0"
4
+
edition = "2024"
+55
08/part1/src/main.rs
···
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
···
1
+
use std::{collections::HashSet, fs::read_to_string};
2
+
3
+
fn main() {
4
+
let boxes: Vec<Vec<u64>> = read_to_string("../input.txt")
5
+
.expect("failed to open input file")
6
+
.lines()
7
+
.map(|jbox| {
8
+
jbox.split(',')
9
+
.map(|coord| coord.parse().unwrap())
10
+
.collect()
11
+
})
12
+
.collect();
13
+
let mut distances: Vec<(_, u64)> = boxes
14
+
.iter()
15
+
.enumerate()
16
+
.flat_map(|(i, jbox)| {
17
+
boxes.iter().enumerate().skip(i + 1).map(move |(j, other)| {
18
+
(
19
+
(i, j),
20
+
jbox.iter()
21
+
.zip(other)
22
+
.map(|(from, to)| from.abs_diff(*to).pow(2))
23
+
.sum(),
24
+
)
25
+
})
26
+
})
27
+
.collect();
28
+
distances.sort_unstable_by_key(|(_, distance)| *distance);
29
+
30
+
let mut circuits: Vec<HashSet<usize>> = Vec::new();
31
+
for ((from, to), _) in distances.into_iter().take(1000) {
32
+
let from_idx = circuits.iter().position(|circuit| circuit.contains(&from));
33
+
let to_idx = circuits.iter().position(|circuit| circuit.contains(&to));
34
+
match (from_idx, to_idx) {
35
+
(Some(from_idx), Some(to_idx)) if from_idx == to_idx => {}
36
+
(Some(from_idx), Some(to_idx)) => {
37
+
let to_circuit: Vec<_> = circuits[to_idx].drain().collect();
38
+
circuits[from_idx].extend(to_circuit);
39
+
circuits.remove(to_idx);
40
+
}
41
+
(Some(from_idx), None) => {
42
+
circuits[from_idx].insert(to);
43
+
}
44
+
(None, Some(to_idx)) => {
45
+
circuits[to_idx].insert(from);
46
+
}
47
+
(None, None) => circuits.push(HashSet::from([from, to])),
48
+
}
49
+
}
50
+
51
+
let mut circuit_sizes: Vec<_> = circuits.into_iter().map(|circuit| circuit.len()).collect();
52
+
circuit_sizes.sort_unstable();
53
+
let result: usize = circuit_sizes.into_iter().rev().take(3).product();
54
+
println!("The result of multiplying the size of the three largest circuits is {result}!");
55
+
}
+4
Cargo.lock
···
57
[[package]]
58
name = "aoc25-07-2"
59
version = "1.0.0"
0
0
0
0
···
57
[[package]]
58
name = "aoc25-07-2"
59
version = "1.0.0"
60
+
61
+
[[package]]
62
+
name = "aoc25-08-1"
63
+
version = "1.0.0"