|
| 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 | +} |
0 commit comments