Day 14 Part 1 Complete -> Really happy with my solution here
This commit is contained in:
parent
9fb69c573b
commit
a3b2847d6b
100
src/input/day14
100
src/input/day14
@ -0,0 +1,100 @@
|
|||||||
|
#....#O##.....O.#...##...#OO.....##...#O...O..........OO......#..OO..O.O...O.O#O#..O...#.......O...#
|
||||||
|
O.....O#..O#O...OO.#.....O#.....O.O..O.O..O.O#.O.#...#...O.#.........#..#O.#......#O.O...#..#.##.##.
|
||||||
|
......##..#.O#..#.O.O......#.O#..O....#.#..#...#.O.#....#....O.#...#O#OOO.##...O............OO#.#..#
|
||||||
|
.OO.................#.#.O.#O.O.#...#..........##.O..#.O##..##O......#O...#.#...O...#......O.........
|
||||||
|
#.......O#...#.OO.##.O.......#...O......O#......#..#.#..O...##..O#..#O.O.....#..OO..O.O.....O.....O#
|
||||||
|
.O..O.OO...#...#O####...##.O.#..O......#O.O..O......O.......O....O....#..O...O.....OOO..#...O.....OO
|
||||||
|
OO.#O.....#.O.#O.#OOO...OO#.........#..O.#O.#O..##O...#.##..#.....#...#.....O...O...............O.OO
|
||||||
|
...OO..#....O.#O.....#.#.#..O...O.#....#....#O...O.........O..##O....O#.O.......OO#.O.O..O......OO..
|
||||||
|
...O....#....#.....O...O.#.O.O...O..#..#.O.....O.#....O#O#.##O....O...#....#......#.....#..O....#..O
|
||||||
|
OOOO#..##...##.....OO..O##.O.OOO#..O...O.#....O..OO##......O..#.O.#.....O.O#.#.#.O....#..........#O.
|
||||||
|
#.OO#O.O..#.O....#..O.OO#..OO...O.O...O.#.O...##.O.....O..OO.#O..#...O.##..#......O#O#OO#...##O.....
|
||||||
|
..#..##...O#.OO#.O.O....###O.O......#....#O..O..O.....O#O.#.....O#....O...#OO.....O###O.....O.OOO.O#
|
||||||
|
O.........OO..O...#.O.#O.#..O...O#.....O#.O...O.OO#.#.#...#...##...O#.OO.OO....O.OOO........#..OO.##
|
||||||
|
.....O..O........OO...OO#O..O.................#...#..#....#.O..#..O#..O..#....O##..#...#O.O.OO#O...#
|
||||||
|
....OO.#OO...O.O.OO.##..OO....O#....O......O..O....O......O...OOO.OO...#.......O.OO....O...OOO#...#.
|
||||||
|
....O......##..O.#O...O.O.O#.##..O.....OO.#..O..O..#.#.O..OO#..#O..#..O##.##..O#.O.O#.O#O#.O.#....O.
|
||||||
|
..O#.O.O#.##....##.O#..O....#O.O#...O....O..O###..#..OO.O..O.....O##..#...#.##.............OOO...OO.
|
||||||
|
O....##.#OOO...#....#...#....#.OO..#.O....O....O.....O##..O.....#....O.OO.O#.O.O.#.#.O#..##.O.O...O.
|
||||||
|
..#.O......#..O.....O.O.......O...O#O.O...O..O......#......##..##....OO......OO..#..O#.O#O#O.#..#...
|
||||||
|
...#O...O..O......O.#......OO..O..#O..#O#O...O.......OO#.#OO..#O....O.......#O.....#....OO....O....#
|
||||||
|
...O.OOOOO..#..O.O.O#..#....O#...##.#..#.O.O.O.......O.....#....#O.O.#O......#.OO...OOO...#....##O..
|
||||||
|
.#.......#.O...##..O.OO....O..#.#..#..O..O...##O.OO#.#.........O........O#.#..#O.....OOO##.#..O...OO
|
||||||
|
...O.....#..O#..##OOO....O.#..O.....OO.##..#OO.#...#O#..O#.OO..#.O....#OO.......O.OO.O.#O##..O.O.O#.
|
||||||
|
...#...###..#..#....#O#..#O......##.O.####.#.....O.O.......O#.#.O#.O..#..#.#...O...#...#O.OO...O....
|
||||||
|
#OO.#O..........#.OOO.....O...##..O.O..O#O.O##O...#...#....#....O.O.#.#O...O.#..O#.OOO..#..#.O...O..
|
||||||
|
.O....#OOO..O..#.#.O.#OOO.......O.#..#...#OO.##.#..OOOO...#.#..#....#..#....O.....#.#.OO....O.......
|
||||||
|
.OO...O#..#............O...#.#.OO.O#OO....#O..#....O.#O.OO......O.O.....O...O.#.....OO.##..#...#O.O.
|
||||||
|
..O..O#O.#OOO....#.OO....O....O..#.#.......#...............O...O....OO.O..#O...OO...#OO........OO...
|
||||||
|
#OO.O...O#.O.O.O#O.#...O.O......O#.O....#O.....O..#O#..O...O.OO.O.#O...O..O..#...O.##.O...OO..O.#O..
|
||||||
|
#..O...#O...OO..O..O.O.O...#.......#.....O.O....#...#..O....#.......##..O.O#.....O........#.....#..O
|
||||||
|
.#....O..O.........#..O...#....#O#..#...O.O.OOO...O...#.....##...##.#...OO#O..O....O..O...O#........
|
||||||
|
...O...O.O..#.#..#O........#####.O#....#O##OOO.O..O.O#.O.......OOOOO....#.##O..#...#.........O..O.OO
|
||||||
|
..#..#...OO#.OO..O....##.O..OO.O.O.#.#O#.O#...O...O.O.#O......OO..O.#.#..O.OO.......###OO.##O....O..
|
||||||
|
........##.O##O#..#......#.....O.O...#..#O#.........#....O...#..O..#....#..#.....O...O.O.O.#..##O.O.
|
||||||
|
.....O...O##...#.#...#O#....OO.....#O.O.O.#.#.#.#.....O..#..O.O.#..#.OOO....OO#...OO.O..O#O...O.#.#O
|
||||||
|
###....O.O..#O......OO.#.OO.##.O...#O.#...O.#.O....O....O....#..#...O..##.#..O.O...O...#.#.#.#.O#...
|
||||||
|
....O#..OO#..#...#.O.OO.O##.O..O...O...#..#.OO.O.O....##....O..O.O.OO...##O..O.#O...O#..#....O#O....
|
||||||
|
#....#....O.#.O...OO....O....#......#O###O##.......O..OO#O...#O#..O...O....##...#..###.O.#..........
|
||||||
|
#O#.#.#.....O.....#.#.O....O....OO#O......O#.#.OO#.....#.OO.O...OO##.O....O.O##...#.............#O..
|
||||||
|
..#.#..###.....O.O..O......O....O....#O.OO.O....OO..#.#O#......O..#..O.##.#.##..O.OO...O......##...#
|
||||||
|
...#.O..#.OO.........O..O.#O......#O..#..O#.O#......O#..OOO.O##....O....#.##O...O.........#O.##...O.
|
||||||
|
.....#O..O.#OO.O....#..OO..O#..O..O#..#.OO.#..O.O...O.....#.#O....O....O##.O.O..##O.O.O..O....#.O#..
|
||||||
|
##.O.O...##..O..O..#O..#.#..O#.#.O.....#..O.##.....O##..#O.#.....O....O....#.OOO#.....O...O....O..#.
|
||||||
|
.....#.O#.O#.O....O.#...#....#.#.....#..#O..#.O......O.O.O...##..OO..O.#..#..#.#...#.#...........OO.
|
||||||
|
....O#.#.O..#....O....#O.O.OO##O.........##O..#O.OO.OO..#....O.O#..###.O......##.O..#.#O..#.....#...
|
||||||
|
....O.O.#.O....#O.....##....#.O......O.......#..#.O.#..#O.#.OO.#.OO..##..O..#O...O.O.OO......O#O....
|
||||||
|
OO..O..O...#.......##OO.........#....O.#.OOO.O..OO..O.....#...O..#..O.....O..#...O.OO.....O#.O.O.O.#
|
||||||
|
.OO#......#O.#......O....#.#..#O..O...#.#.........OO..........O..O.....O.O..O##.O...O.O...#.........
|
||||||
|
..#.#OO.OO........#O..O...#O#OO...#..O..#.##.OO.#.....O..O.OOO..#..#.#....OO...##.OO..O#....O....O.O
|
||||||
|
.#.#.#..O.OO..O......O...O#O.OO.......#...O...O.#O...OO..O#.O.#.##............##.OOO#.OOO..#O.O#...O
|
||||||
|
......O...##OO.....#.##O#....#OO.O....#.#....#.....O.O......#...O.O#.##...O#............#....O#O.O.O
|
||||||
|
.O....#...O....#.##O.....O##.......#...O.....#....O.#O#.O..OO#O...#.........#...OO.O##..#..##....#.#
|
||||||
|
##O.#O......O..#.#...##.##.O##.#.....#OO#..#.........#O.O...#......#..O..O.O##..O.OO......O#O#O#..#.
|
||||||
|
......#.O#O.O...#O.OO.....O...O##.#.OO#..OO....#O..#....#.....O.#O.O.#O#..OO..O..#O.#.....O#......##
|
||||||
|
....###.......OO#O...O..#..#.#.....#.#...O..OO#.O..#OO#.O..O....OO.O.#.##O..#..O...OO.#.O.#......#..
|
||||||
|
#O.O....#...#.O..O..####....O#........O....O#..O..O..OO..OO...OOO..O..OOO......#.#....O..##.O#..#O##
|
||||||
|
..........O.#.O.O#..#.O..O#.#....#...#.##OO..OOO.....O##O#....#O.#....#.O...#O#.O.#.##..#O.O#.......
|
||||||
|
.....#...#O#......O#.O..........#O.O.OO..O..OO.#.............O#.#........O#.OOO##O...O.O#.#...#.....
|
||||||
|
O..O..O.........OO#...O.O...O....#.#.#...OO#...OOO...O........#.#O.OO#.O.....O.O..O#.OOO.O...O.OO...
|
||||||
|
OO#....#..O.#.O.O##O##.........#..O..#.O.##..O.##.#.OO..O.....##..#......OO..#...#...O..O..#.OO.#.O.
|
||||||
|
#.O....#..#.....#.##.#...O.O...O.O...O#...#...O..O...#...#..O.#.O#.OO.#....O....O#..#.O##...#...#..#
|
||||||
|
##...O..#.#......#O.O...#O.....#......OO...#OO..O......#.#..........O#..O..O..O.O.O....O...O...#O..#
|
||||||
|
..##.#O.#.OOO..O...O..O.O..O...##.....OOO#..O......#..O...........#O......O..#OO#..O.O.##....OO..O#.
|
||||||
|
.#..............O#..#..O#O...OO###.##....O.#.##..###.#O.#....#...#.OO.O#....O..OO..#OO#.O..........O
|
||||||
|
...#.#...#OO........#.O..#.O...#.O.O.#.....#......O#......#....#.##O.###.O....##.....O#OO.O....O##..
|
||||||
|
.O.O......O..#.....O......##O#..#..OO..#.#..O...#.O..#O.O#OO..#..O#.O....#...#O..O..#..O#.O.....O.OO
|
||||||
|
O.#.O.OO.OO.O......O..#.O...O#O..OO......O...#......O..O#O..##O.#OO....O......OO......#O......#...O.
|
||||||
|
.#O..O.#O..O.O#..O.#...#...O##O....#O.O##..#OO.....O..OO#.O##...#....#..##..OO.OO#..O...OO.....#.#.#
|
||||||
|
O#.OOO.#O..O.O#.O#O......OO...#O....O............#..#........#.O##..#O.O###.OO..#...#.....O........O
|
||||||
|
O......O.OO..#.#..#.......OOO.#.#........................O#O.#..O..........##.#..O#.......#.#....O..
|
||||||
|
O.#O...O#.#O.......O##O..#..O.#.#O.O.O...#OO..O.O##O.....O....OOO...##..OO....#.#..##...#..O.#.O.#.O
|
||||||
|
#..#.#O.#..##....OOO.....O......O.#O..#O..O.#O.O.#....O...O#.OO##..#...O###....###..#..O.#.O...#....
|
||||||
|
...O.......O.O.......#.#OOO....O.......#..O...O.........##..#.O.#O.O......#..OO.O.O......#.....OO...
|
||||||
|
O.....#O.#.#....#..#.O.OOO...#.O###......OO...O.O.O.###...O.O.......##..#......#..OO.O.....OO...O.OO
|
||||||
|
O.O.....#.#.#....O#OOO.....O.....#O...##O..#OO.O.......O.O.......#.O.#.........#..........O...#.OOO.
|
||||||
|
O....OO.#.#O##.O....#O#.OO..O...OO.#.#O.#.#.O...O#O...OO.#.O...##...OO..#OO.#......#O......#....O.O.
|
||||||
|
O...O......O..#..#.#...##..O..#.O.O......#....#.....O#O.O....O.#..O..............#.O...#...OO.....O#
|
||||||
|
....OO.......O...##O..#.O#..O#..O..O#.#.O#.#..O.O..#.......#O..OO.O.#....#..#.......OO..OOO.#O#...O.
|
||||||
|
.#.....O......O..O...O....#...OOO#...O#.#.#.#.OO.O.O...#..O..O#......#.O.....O.O.O....#...O#.....#.O
|
||||||
|
...O#........O......OOO..#.OO#.O.#.O..##......#.#O...O.O...O.#O.OO.OO..#..O...O.........#.O##..OO##.
|
||||||
|
..O..O.#O..#O..##....O.O.#O...O#.O.....##.....O......#...#.....OOO..O##.O#..#.#.O.......#O...O#...##
|
||||||
|
...O.OO..O.#.OO#....#.O#O..O...#O.O.###...##...O.O..#..O..#.O....#........#...#....O...O....#O#O.O.#
|
||||||
|
...OO.#...O...OOO..O.....#..#.O.#OO...O...O..#..O..O.O...O..#.#O.#OO.O.....O.O..#...O..O..O#.O#O...#
|
||||||
|
O...#...##.OO..OO.......#..O.O..OO.OO.O#......#.O#O.O.#..O.#.O.O.O#OO...#.....##O.OO.#OO....O...###.
|
||||||
|
O.............#.#..#.O....#....O...#..O..O#.O...OO.O.O........O#.O........OO..#....O...#O#O#.O.#OO.O
|
||||||
|
OO.........O...#.O.O...#.....O...#.OO#O.##............#....O....##.##..#.O..O....OO...OOO..O........
|
||||||
|
O.....#....O.#O..OO.O#.......#.....#....#.....##OO#..O..#OO.....#.....#..OO#..O#..O.O#OO.O.O...O.OO.
|
||||||
|
OO#....O....O#....#O#.....#.....O.#O#..OO.OO.O..#..O....#O..O#.#O#..OOO...##...#..#...O..O...O#..O#.
|
||||||
|
O......O#...O.#......O.O..#..O.#.....O...O...OO###...#.OO......O..O....#..O#.O....#..#.#..#.OO..O...
|
||||||
|
...#...#O#O.......#.O#.O....OOO.O..OO#.O.O..O#....O....#OO..O.......O.#..#...#.....O...O.O..O..O.#..
|
||||||
|
.O#..#.O#.#O#.O#..O..#....#O#..#.O.##.O.OOOO.#O..O#....O..OOO.......OO.#...O..O#O..O#...#O...O.#....
|
||||||
|
O.#.O.#.O...O.#.......#O.O#O.##..#...#...O#...O#O#O.#O...O..O.....#.O.##OO.O...O#.#...O.O#...#..O###
|
||||||
|
O.......O#..#......#....OO.O.#O..##O...OOO.O....O..#O....#.#..##OOO.OO#.....#..O.O...#O...O..O.O..OO
|
||||||
|
...O..O#O.O..O...##.....O.O.#O........O.###O#..#...#.OO.#.O.....OOO.#.......O..O.OO..O#...O.....O#..
|
||||||
|
........#..O#..#O.#OO.O.O..#.##..#O..#.O......O.O.#O.O.......#O#..O..##..O#.......O.#..O.#.O.O.O#O..
|
||||||
|
#..O....O.....#.O....O..##....O...O........#O....#...#..O....#....#..#O.O.......O.OOO..#...OO...#.#.
|
||||||
|
.O.O..#OO..O..O.O.........##..O...........OO..O.O.....OO...O#.#.......#...O#O...#..O.O...O.O#...#...
|
||||||
|
O.....#O.......O#..O..O..##O..#.......#...#.O......O...O..#...O..O..OO.#O..O..O.#......OO...#...OO#O
|
||||||
|
..###O.........O..#.#.#.#.O..O.#....#...#..O##O#..#O#.O#OO.O.O....O.....#O...#..O..#O..O....#.....#.
|
||||||
|
....O#.O..#......#..OOO..#.O.O...O.#O.......O.O.#####..#.....#.#.#....#...O#..O.O.O.O...O..#.......O
|
@ -0,0 +1,10 @@
|
|||||||
|
O....#....
|
||||||
|
O.OO#....#
|
||||||
|
.....##...
|
||||||
|
OO.#O....O
|
||||||
|
.O.....O#.
|
||||||
|
O.#..O.#.#
|
||||||
|
..O..#O..O
|
||||||
|
.......O..
|
||||||
|
#....###..
|
||||||
|
#OO..#....
|
@ -0,0 +1,10 @@
|
|||||||
|
O....#....
|
||||||
|
O.OO#....#
|
||||||
|
.....##...
|
||||||
|
OO.#O....O
|
||||||
|
.O.....O#.
|
||||||
|
O.#..O.#.#
|
||||||
|
..O..#O..O
|
||||||
|
.......O..
|
||||||
|
#....###..
|
||||||
|
#OO..#....
|
@ -21,7 +21,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
Box::new(day11::Day11 {}),
|
Box::new(day11::Day11 {}),
|
||||||
Box::new(day12::Day12 {}),
|
Box::new(day12::Day12 {}),
|
||||||
Box::new(day13::Day13 {}),
|
Box::new(day13::Day13 {}),
|
||||||
// Box::new(day14::Day14 {}),
|
Box::new(day14::Day14 {}),
|
||||||
// Box::new(day15::Day15 {}),
|
// Box::new(day15::Day15 {}),
|
||||||
// Box::new(day16::Day16 {}),
|
// Box::new(day16::Day16 {}),
|
||||||
// Box::new(day17::Day17 {}),
|
// Box::new(day17::Day17 {}),
|
||||||
|
@ -5,9 +5,16 @@ pub struct Day14 {}
|
|||||||
impl Solution for Day14 {
|
impl Solution for Day14 {
|
||||||
fn part1(
|
fn part1(
|
||||||
&self,
|
&self,
|
||||||
_input: &mut Vec<String>,
|
input: &mut Vec<String>,
|
||||||
) -> Result<Box<dyn std::fmt::Display + Sync>, Box<dyn std::error::Error>> {
|
) -> Result<Box<dyn std::fmt::Display + Sync>, Box<dyn std::error::Error>> {
|
||||||
Ok(Box::new("Ready"))
|
let mut rock_formation = input
|
||||||
|
.iter()
|
||||||
|
.map(|r| r.chars().collect::<Vec<_>>())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
self.pull_north(&mut rock_formation);
|
||||||
|
|
||||||
|
Ok(Box::new(self.get_load(&rock_formation)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2(
|
fn part2(
|
||||||
@ -22,7 +29,37 @@ impl Solution for Day14 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Day14 {}
|
impl Day14 {
|
||||||
|
// Function that pulls all of the 'O's as far north as they will go
|
||||||
|
fn pull_north(&self, cave: &mut Vec<Vec<char>>) {
|
||||||
|
let mut complete = false;
|
||||||
|
|
||||||
|
while !complete {
|
||||||
|
complete = true;
|
||||||
|
for row in 1..cave.len() {
|
||||||
|
for col in 0..cave[0].len() {
|
||||||
|
if cave[row][col] == 'O' && cave[row - 1][col] == '.' {
|
||||||
|
cave[row][col] = '.';
|
||||||
|
cave[row - 1][col] = 'O';
|
||||||
|
complete = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function that calculates the load on the north beams of the cave
|
||||||
|
fn get_load(&self, cave: &Vec<Vec<char>>) -> u32 {
|
||||||
|
(0..cave.len())
|
||||||
|
.map(|row| {
|
||||||
|
(0..cave[0].len())
|
||||||
|
.filter(|col| cave[row][*col] == 'O')
|
||||||
|
.map(|_| cave.len() - row)
|
||||||
|
.sum::<usize>()
|
||||||
|
})
|
||||||
|
.sum::<usize>() as u32
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Test from puzzle input
|
/// Test from puzzle input
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -44,7 +81,7 @@ mod test {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
assert_eq!(answer, "Ready");
|
assert_eq!(answer, "136");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user