Skip to content

Commit e71638c

Browse files
committed
Add day10 - wip
1 parent a4bb2ba commit e71638c

File tree

3 files changed

+106
-7
lines changed

3 files changed

+106
-7
lines changed

src/day10.rs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
use aoc_runner_derive::{aoc, aoc_generator};
2+
3+
#[aoc_generator(day10)]
4+
pub fn input_generator(input: &str) -> Vec<Vec<usize>> {
5+
input
6+
.lines()
7+
.map(|s| {
8+
s.chars()
9+
.map(|l| l.to_digit(10).unwrap() as usize)
10+
.collect()
11+
})
12+
.collect()
13+
}
14+
15+
// #[memoize]
16+
// pub fn blink(stone: usize, counter: usize, limit: usize) -> usize {
17+
// let mut stack = 0;
18+
// if counter == limit {
19+
// return 1;
20+
// }
21+
22+
// if stone == 0 {
23+
// stack += blink(1, counter + 1, limit);
24+
// } else {
25+
// let mut div = stone;
26+
// let mut count = 0;
27+
// while div > 0 {
28+
// div /= 10;
29+
// count += 1;
30+
// }
31+
// if count % 2 == 0 {
32+
// stack += blink(stone / 10_usize.pow(count / 2), counter + 1, limit);
33+
// stack += blink(stone % 10_usize.pow(count / 2), counter + 1, limit);
34+
// } else {
35+
// stack += blink(stone * 2024, counter + 1, limit);
36+
// }
37+
// }
38+
// stack
39+
// }
40+
41+
#[aoc(day10, part1)]
42+
pub fn part1(input: &[Vec<usize>]) -> usize {
43+
// let directions = [
44+
// (0, 1), // right
45+
// (0, -1), // left
46+
// (1, 0), // up
47+
// (-1, 0), // down
48+
// ];
49+
// for (row_idx, row) in input.iter().enumerate() {
50+
// dbg!(row_idx, row);
51+
// for (col_idx, col) in row.iter().enumerate() {
52+
// dbg!(col_idx, col);
53+
// if *col == 0 {
54+
// for &(dy, dx) in &directions {
55+
// let ny: isize = y as isize + i * dy;
56+
// let nx = x as isize + i * dx;
57+
// if ny >= 0
58+
// && ny < input.len() as isize
59+
// && nx >= 0
60+
// && nx < input[y].len() as isize
61+
// {
62+
// match *col {}
63+
// }
64+
// }
65+
// // match input[row_idx][col_idx + 1]
66+
// }
67+
// }
68+
// }
69+
0
70+
}
71+
72+
// #[aoc(day10, part2)]
73+
// pub fn part2(input: &[usize]) -> usize {
74+
// let mut lenght = 0;
75+
// for stone in input {
76+
// lenght += blink(*stone, 0, 75);
77+
// }
78+
// lenght
79+
// }
80+
81+
#[cfg(test)]
82+
mod tests {
83+
use super::*;
84+
85+
const INPUT: &str = "89010123
86+
78121874
87+
87430965
88+
96549874
89+
45678903
90+
32019012
91+
01329801
92+
10456732";
93+
94+
#[test]
95+
fn test_part1() {
96+
assert_eq!(55312, part1(&input_generator(INPUT)))
97+
}
98+
99+
// #[test]
100+
// fn test_part2() {
101+
// assert_eq!(55312, part2(&input_generator(INPUT)))
102+
// }
103+
}

src/day11.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@ pub fn blink(stone: usize, counter: usize, limit: usize) -> usize {
1616
if stone == 0 {
1717
stack += blink(1, counter + 1, limit);
1818
} else {
19-
let mut div = stone;
20-
let mut count = 0;
21-
while div > 0 {
22-
div /= 10;
23-
count += 1;
24-
}
19+
let count = stone.ilog10() + 1;
2520
if count % 2 == 0 {
2621
stack += blink(stone / 10_usize.pow(count / 2), counter + 1, limit);
2722
stack += blink(stone % 10_usize.pow(count / 2), counter + 1, limit);
@@ -63,7 +58,7 @@ mod tests {
6358

6459
#[test]
6560
fn test_part2() {
66-
assert_eq!(55312, part2(&input_generator(INPUT)))
61+
assert_eq!(65601038650482, part2(&input_generator(INPUT)))
6762
}
6863
}
6964

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use aoc_runner_derive::aoc_lib;
22

33
mod day1;
4+
mod day10;
45
mod day11;
56
mod day2;
67
mod day3;

0 commit comments

Comments
 (0)