Day 14 Part 1 Complete -> Really happy with my solution here

This commit is contained in:
Luke Else 2023-12-14 17:38:01 +00:00
parent 9fb69c573b
commit a3b2847d6b
5 changed files with 163 additions and 6 deletions

View File

@ -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

View File

@ -0,0 +1,10 @@
O....#....
O.OO#....#
.....##...
OO.#O....O
.O.....O#.
O.#..O.#.#
..O..#O..O
.......O..
#....###..
#OO..#....

View File

@ -0,0 +1,10 @@
O....#....
O.OO#....#
.....##...
OO.#O....O
.O.....O#.
O.#..O.#.#
..O..#O..O
.......O..
#....###..
#OO..#....

View File

@ -21,7 +21,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
Box::new(day11::Day11 {}),
Box::new(day12::Day12 {}),
Box::new(day13::Day13 {}),
// Box::new(day14::Day14 {}),
Box::new(day14::Day14 {}),
// Box::new(day15::Day15 {}),
// Box::new(day16::Day16 {}),
// Box::new(day17::Day17 {}),

View File

@ -5,9 +5,16 @@ pub struct Day14 {}
impl Solution for Day14 {
fn part1(
&self,
_input: &mut Vec<String>,
input: &mut Vec<String>,
) -> 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(
@ -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
#[cfg(test)]
@ -44,7 +81,7 @@ mod test {
.unwrap()
.to_string();
assert_eq!(answer, "Ready");
assert_eq!(answer, "136");
}
#[test]