Skip to content

Commit 58f2d5d

Browse files
committed
variables
1 parent 270fcad commit 58f2d5d

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed

src/bin/2025_07/main.rs

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,74 +6,82 @@ use aoc::{
66
};
77

88
fn solve2(input: &str) -> usize {
9-
let mut ans = 0;
9+
let mut ans2 = 0;
1010
let grid = Grid::from_str(input, |c| c);
1111
let mut pos = grid.positions(&'S');
1212
pos[0].0 += 1;
13-
let tcs = grid.positions(&'^');
14-
let emt = grid.positions(&'.');
13+
let tachyons = grid.positions(&'^');
14+
let empty_spaces = grid.positions(&'.');
1515

16-
let mut post = HashMap::new();
17-
post.insert(pos[0], 1);
16+
let mut space_time = HashMap::new();
17+
space_time.insert(pos[0], 1);
1818

19-
while !post.is_empty() {
20-
let mut new_post: HashMap<CellIndex, usize> = HashMap::new();
19+
while !space_time.is_empty() {
20+
let mut new_space_time: HashMap<CellIndex, usize> = HashMap::new();
2121

22-
for (p, t) in post {
23-
if emt.contains(&p) {
22+
for (p, t) in space_time {
23+
if empty_spaces.contains(&p) {
2424
let new_p = (p.0 + 1, p.1);
25-
if let Some(x) = new_post.get_mut(&new_p) {
25+
if let Some(x) = new_space_time.get_mut(&new_p) {
2626
*x += t;
2727
} else {
28-
new_post.insert(new_p, t);
28+
new_space_time.insert(new_p, t);
2929
}
3030
}
31-
if tcs.contains(&p) {
31+
if tachyons.contains(&p) {
3232
if p.1 > 0 {
3333
let new_p = (p.0 + 1, p.1 - 1);
34-
if let Some(x) = new_post.get_mut(&new_p) {
34+
if let Some(x) = new_space_time.get_mut(&new_p) {
3535
*x += t;
3636
} else {
37-
new_post.insert(new_p, t);
37+
new_space_time.insert(new_p, t);
3838
}
3939
}
4040
if p.1 + 1 < grid.cols {
4141
let new_p = (p.0 + 1, p.1 + 1);
42-
if let Some(x) = new_post.get_mut(&new_p) {
42+
if let Some(x) = new_space_time.get_mut(&new_p) {
4343
*x += t;
4444
} else {
45-
new_post.insert(new_p, t);
45+
new_space_time.insert(new_p, t);
4646
}
4747
}
4848
}
4949
}
5050

51-
if new_post.is_empty() {
51+
if new_space_time.is_empty() {
5252
break;
5353
}
5454

55-
ans = new_post.values().sum::<usize>();
56-
post = new_post;
55+
ans2 = new_space_time.values().sum::<usize>();
56+
space_time = new_space_time;
5757
}
5858

5959
//grid.print();
60-
ans
60+
ans2
6161
}
6262

63-
fn solve<const PART: usize>(input: &str) -> usize {
63+
fn solve1(input: &str) -> usize {
6464
let mut ans = 0;
6565
let grid = Grid::from_str(input, |c| c);
6666
let mut pos = grid.positions(&'S');
6767
pos[0].0 += 1;
68-
let tcs = grid.positions(&'^');
69-
let emt = grid.positions(&'.');
68+
let tachyons = grid.positions(&'^');
69+
let empty_spaces = grid.positions(&'.');
7070

7171
while !pos.is_empty() {
72-
let cnt_emt: Vec<CellIndex> = emt.iter().filter(|x| pos.contains(x)).map(|x| *x).collect();
73-
let cnt: Vec<CellIndex> = tcs.iter().filter(|x| pos.contains(x)).map(|x| *x).collect();
72+
let cnt_empty_spaces: Vec<CellIndex> = empty_spaces
73+
.iter()
74+
.filter(|x| pos.contains(x))
75+
.map(|x| *x)
76+
.collect();
77+
let cnt: Vec<CellIndex> = tachyons
78+
.iter()
79+
.filter(|x| pos.contains(x))
80+
.map(|x| *x)
81+
.collect();
7482
let mut new_pos = HashSet::new();
7583

76-
for c in &cnt_emt {
84+
for c in &cnt_empty_spaces {
7785
new_pos.insert((c.0 + 1, c.1));
7886
}
7987

@@ -95,7 +103,7 @@ fn solve<const PART: usize>(input: &str) -> usize {
95103

96104
fn main() {
97105
if let Some(input) = common::get_input() {
98-
common::timed(&input, solve::<1>, true);
106+
common::timed(&input, solve1, true);
99107
common::timed(&input, solve2, false);
100108
}
101109
}
@@ -107,7 +115,7 @@ mod tests {
107115
#[test]
108116
fn test_samples() {
109117
let sample_input = ".......S.......\n...............\n.......^.......\n...............\n......^.^......\n...............\n.....^.^.^.....\n...............\n....^.^...^....\n...............\n...^.^...^.^...\n...............\n..^...^.....^..\n...............\n.^.^.^.^.^...^.\n...............";
110-
assert_eq!(solve::<1>(sample_input), 21);
118+
assert_eq!(solve1(sample_input), 21);
111119
assert_eq!(solve2(sample_input), 40);
112120
}
113121
}

0 commit comments

Comments
 (0)