finished day07

This commit is contained in:
2025-12-09 22:04:29 +01:00
parent bf0d592eba
commit f91772c4bf
4 changed files with 68 additions and 20 deletions

View File

@@ -1,23 +1,23 @@
# Advent of Code 2025 # Advent of Code 2025
```bash ```bash
day01:A => 1150 ( 56us) day01:A => 1150 ( 49us)
day01:B => 1150 ( 55us) day01:B => 1150 ( 47us)
day02:A => 31839939622 ( 7769us) day02:A => 31839939622 ( 7731us)
day02:B => 41662374059 ( 64866us) day02:B => 41662374059 ( 64732us)
day03:A => 16812 ( 81us) day03:A => 16812 ( 84us)
day03:B => 166345822896410 ( 275us) day03:B => 166345822896410 ( 286us)
day04:A => 1518 ( 195us) day04:A => 1518 ( 202us)
day04:B => 8665 ( 3720us) day04:B => 8665 ( 3737us)
day05:A => 701 ( 139us) day05:A => 701 ( 140us)
day05:B => 352340558684863 ( 19us) day05:B => 352340558684863 ( 19us)
day06:A => 6503327062445 ( 194us) day06:A => 6503327062445 ( 207us)
day06:B => 9640641878593 ( 132us) day06:B => 9640641878593 ( 133us)
day07:A => 0 ( 0us) day07:A => 1678 ( 49us)
day07:B => 0 ( 0us) day07:B => 357525737893560 ( 55us)
day08:A => 0 ( 0us) day08:A => 0 ( 0us)
day08:B => 0 ( 0us) day08:B => 0 ( 0us)
day09:A => 4725826296 ( 162us) day09:A => 4725826296 ( 164us)
day09:B => 0 ( 0us) day09:B => 0 ( 0us)
---------- ----------
78285us 81857us
``` ```

View File

@@ -23,14 +23,12 @@ mod tests {
..............."; ...............";
#[test] #[test]
#[ignore]
fn part07a() { fn part07a() {
assert_eq!(part07a::solve(PUZZLE.to_string()), 21); assert_eq!(part07a::solve(PUZZLE.to_string()), 21);
} }
#[test] #[test]
#[ignore]
fn part07b() { fn part07b() {
assert_eq!(part07b::solve(PUZZLE.to_string()), 0); assert_eq!(part07b::solve(PUZZLE.to_string()), 40);
} }
} }

View File

@@ -1,4 +1,29 @@
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: String) -> u64 {
0 // TODO let mut solution = 0;
let mut lines = puzzle.lines();
let mut source = lines
.next()
.unwrap()
.chars()
.map(|c| match c { 'S' => 1, _ => 0 } )
.collect::<Vec<u8>>();
lines.for_each(|line| {
let mut next_source = source.clone();
line.chars().zip(source.iter()).enumerate().for_each(|(i, x)| {
match x {
('^', 1) => {
solution += 1;
next_source[i-1] = 1;
next_source[i] = 0;
next_source[i+1] = 1;
},
_ => (),
}
});
source = next_source;
});
solution
} }

View File

@@ -1,4 +1,29 @@
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: String) -> u64 {
0 // TODO let mut solution = 0;
let mut lines = puzzle.lines();
let mut source = lines
.next()
.unwrap()
.chars()
.map(|c| match c { 'S' => (1, 1), _ => (0, 0) } )
.collect::<Vec<(u8, u64)>>();
lines.for_each(|line| {
let mut next_source = source.clone();
line.chars().zip(source.iter()).enumerate().for_each(|(i, x)| {
match x {
('^', (1, weight)) => {
solution += weight;
next_source[i-1] = (1 , next_source[i-1].1 + weight);
next_source[i] = (0, 0);
next_source[i+1] = (1 , next_source[i+1].1 + weight)
},
_ => (),
}
});
source = next_source;
});
solution + 1
} }