# HG changeset patch # User IBBoard # Date 1702722576 0 # Node ID 46fb65f2cb94180bc29c793fa2784d61ead0c14f # Parent fac484765bc964248d6d0e08f17bcb17fa9b750f Add Day 14 part 1 implementation If you look at columns and see "how far can this go" then the weight is just the sum of the partial triangle numbers of highest_weight to highest_weight minus number of rocks that can roll up to there. Part 2 seems to involve actually moving the rocks, though! diff -r fac484765bc9 -r 46fb65f2cb94 day14.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/day14.rb Sat Dec 16 10:29:36 2023 +0000 @@ -0,0 +1,27 @@ +#! /usr/bin/env ruby + +if ARGV.length != 1 + abort("Incorrect arguments - needs input file") +elsif not File.exist? (ARGV[0]) + abort("File #{ARGV[0]} did not exist") +end + +file = ARGV[0] + +platform = File.open(file, "r").each_line(chomp: true).map {|row| row.each_char.to_a}.to_a.transpose() + +COL_SIZE = platform[0].length + +chunked_platform = platform.map {|col| col.chunk_while {|i, j| i != "#"}.to_a} +total_load = chunked_platform.reduce(0) do |weight, col| + _, col_weight = col.reduce([COL_SIZE, 0]) do |accum, chunk| + first_obj_weight, temp_weight = accum + num_moved_objs = chunk.count("O") + last_obj_weight = first_obj_weight - num_moved_objs + temp_weight += ((first_obj_weight * (first_obj_weight + 1)) / 2) - ((last_obj_weight * (last_obj_weight + 1)) / 2) + first_obj_weight -= chunk.length + [first_obj_weight, temp_weight] + end + weight + col_weight +end +puts total_load \ No newline at end of file diff -r fac484765bc9 -r 46fb65f2cb94 day14.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/day14.txt Sat Dec 16 10:29:36 2023 +0000 @@ -0,0 +1,92 @@ +--- Day 14: Parabolic Reflector Dish --- + +Given movable objects (O) and stationary objects (#) with free space (.), +"tilt" the map to the top so that the movable objects slide to the top +of the map and then determine the total "load" - the sum of the number +of rows from the movable object to the bottom of the map. + +Given: + +O....#.... +O.OO#....# +.....##... +OO.#O....O +.O.....O#. +O.#..O.#.# +..O..#O..O +.......O.. +#....###.. +#OO..#.... + +Sliding makes it: + +OOOO.#.O.. +OO..#....# +OO..O##..O +O..#.OO... +........#. +..#....#.# +..O..#.O.O +..O....... +#....###.. +#....#.... + +The load calculation is: + +OOOO.#.O.. 10 +OO..#....# 9 +OO..O##..O 8 +O..#.OO... 7 +........#. 6 +..#....#.# 5 +..O..#.O.O 4 +..O....... 3 +#....###.. 2 +#....#.... 1 + +Which gives 136. + +Given a huge map, what is the load? + +--- Part 2 --- + +Now we want to cycle them by shifting them all in a cycle north, west, south and east. + +After 1 cycle: +.....#.... +....#...O# +...OO##... +.OO#...... +.....OOO#. +.O#...O#.# +....O#.... +......OOOO +#...O###.. +#..OO#.... + +After 2 cycles: +.....#.... +....#...O# +.....##... +..O#...... +.....OOO#. +.O#...O#.# +....O#...O +.......OOO +#..OO###.. +#.OOO#...O + +After 3 cycles: +.....#.... +....#...O# +.....##... +..O#...... +.....OOO#. +.O#...O#.# +....O#...O +.......OOO +#...O###.O +#.OOO#...O + + +What is the top load after 1,000,000,000 cycles? \ No newline at end of file