From: Brett Parker Date: Tue, 8 Dec 2020 11:06:20 +0000 (+0000) Subject: Day 11 - part 2 and output, and some notes X-Git-Url: https://git.sommitrealweird.co.uk/advent-of-code-2019.git/commitdiff_plain/762c474265f967e401c9dfd52efdf81b2eeed9f0?ds=sidebyside Day 11 - part 2 and output, and some notes --- diff --git a/day11/notes.txt b/day11/notes.txt new file mode 100644 index 0000000..29b00fd --- /dev/null +++ b/day11/notes.txt @@ -0,0 +1,7 @@ +registration.txt is the image generated by run2.sh + +run.sh runs the first part +run2.sh runs the second part + +robot.sh - the functions / variables for the robot +computer.sh - the Intcode interpreter diff --git a/day11/registration.txt b/day11/registration.txt new file mode 100644 index 0000000..0ba21e8 --- /dev/null +++ b/day11/registration.txt @@ -0,0 +1,6 @@ +.###...##..#..#.###..#....###..#..#.#..#... +.#..#.#..#.#.#..#..#.#....#..#.#..#.#.#.... +.#..#.#....##...#..#.#....#..#.#..#.##..... +.###..#....#.#..###..#....###..#..#.#.#.... +.#....#..#.#.#..#.#..#....#....#..#.#.#.... +.#.....##..#..#.#..#.####.#.....##..#..#... diff --git a/day11/robot.sh b/day11/robot.sh index c5b5613..79f87a8 100644 --- a/day11/robot.sh +++ b/day11/robot.sh @@ -39,7 +39,7 @@ get_paint_colour() { if [ ${__robot_grid[$x,$y]+a} ]; then echo ${__robot_grid[$x,$y]} else - if [ $x -eq 0 ] && [ $y -eq 0 ] && [ $__start_on_white -eq 1 ]; then + if [ $x -eq 0 ] && [ $y -eq 0 ] && [ $__robot_start_on_white -eq 1 ]; then echo 1 else echo 0 @@ -140,7 +140,9 @@ do_robot_paint_and_move() { draw_panel() { colours=("." "#") - for (( y=$__robot_lowest_y; y<=$__robot_highest_y; y++ )); do + # we draw upside down, in effect, starting from the bottom and going to + # the top, so when outputting, we should switch that round + for (( y=$__robot_highest_y; y>=$__robot_lowest_y; y-- )); do for (( x=$__robot_lowest_x; x<=$__robot_highest_x; x++ )); do echo -n ${colours[$(get_paint_colour $x $y)]} done diff --git a/day11/run2.sh b/day11/run2.sh index 9520560..2a650d5 100755 --- a/day11/run2.sh +++ b/day11/run2.sh @@ -14,10 +14,14 @@ base_dir=$(dirname $(readlink -f $BASH_SOURCE)) . computer.sh . robot.sh -# start the computer as a coproc coproc computer (run_program data) -while ( kill -0 $computer_PID >/dev/null 2>&1 ); do +reset_robot +set_robot_start_on_white 1 + +check_pid=$computer_PID + +while ( kill -0 $check_pid > /dev/null 2>&1 ); do get_robot_paint_colour >&${computer[1]} read -u ${computer[0]} direction read -u ${computer[0]} colour @@ -28,8 +32,5 @@ done # just incase the spinner is still about echo -n $'\r'" "$'\r' -# we've done all the painting, now lets display it +echo "Part 2:" draw_panel - -echo -echo "Painted: $(get_robot_paint_count) panels at least once" diff --git a/day11/summary.txt b/day11/summary.txt new file mode 100644 index 0000000..332d3fa --- /dev/null +++ b/day11/summary.txt @@ -0,0 +1,76 @@ +--- Day 11: Space Police --- +On the way to Jupiter, you're pulled over by the Space Police. + +"Attention, unmarked spacecraft! You are in violation of Space Law! All spacecraft must have a clearly visible registration identifier! You have 24 hours to comply or be sent to Space Jail!" + +Not wanting to be sent to Space Jail, you radio back to the Elves on Earth for help. Although it takes almost three hours for their reply signal to reach you, they send instructions for how to power up the emergency hull painting robot and even provide a small Intcode program (your puzzle input) that will cause it to paint your ship appropriately. + +There's just one problem: you don't have an emergency hull painting robot. + +You'll need to build a new emergency hull painting robot. The robot needs to be able to move around on the grid of square panels on the side of your ship, detect the color of its current panel, and paint its current panel black or white. (All of the panels are currently black.) + +The Intcode program will serve as the brain of the robot. The program uses input instructions to access the robot's camera: provide 0 if the robot is over a black panel or 1 if the robot is over a white panel. Then, the program will output two values: + +First, it will output a value indicating the color to paint the panel the robot is over: 0 means to paint the panel black, and 1 means to paint the panel white. +Second, it will output a value indicating the direction the robot should turn: 0 means it should turn left 90 degrees, and 1 means it should turn right 90 degrees. +After the robot turns, it should always move forward exactly one panel. The robot starts facing up. + +The robot will continue running for a while like this and halt when it is finished drawing. Do not restart the Intcode computer inside the robot during this process. + +For example, suppose the robot is about to start running. Drawing black panels as ., white panels as #, and the robot pointing the direction it is facing (< ^ > v), the initial state and region near the robot looks like this: + +..... +..... +..^.. +..... +..... +The panel under the robot (not visible here because a ^ is shown instead) is also black, and so any input instructions at this point should be provided 0. Suppose the robot eventually outputs 1 (paint white) and then 0 (turn left). After taking these actions and moving forward one panel, the region now looks like this: + +..... +..... +.<#.. +..... +..... +Input instructions should still be provided 0. Next, the robot might output 0 (paint black) and then 0 (turn left): + +..... +..... +..#.. +.v... +..... +After more outputs (1,0, 1,0): + +..... +..... +..^.. +.##.. +..... +The robot is now back where it started, but because it is now on a white panel, input instructions should be provided 1. After several more outputs (0,1, 1,0, 1,0), the area looks like this: + +..... +..<#. +...#. +.##.. +..... +Before you deploy the robot, you should probably have an estimate of the area it will cover: specifically, you need to know the number of panels it paints at least once, regardless of color. In the example above, the robot painted 6 panels at least once. (It painted its starting panel twice, but that panel is still only counted once; it also never painted the panel it ended on.) + +Build a new emergency hull painting robot and run the Intcode program on it. How many panels does it paint at least once? + +Your puzzle answer was 2373. + +--- Part Two --- +You're not sure what it's trying to paint, but it's definitely not a registration identifier. The Space Police are getting impatient. + +Checking your external ship cameras again, you notice a white panel marked "emergency hull painting robot starting panel". The rest of the panels are still black, but it looks like the robot was expecting to start on a white panel, not a black one. + +Based on the Space Law Space Brochure that the Space Police attached to one of your windows, a valid registration identifier is always eight capital letters. After starting the robot on a single white panel instead, what registration identifier does it paint on your hull? + +Your puzzle answer was PCKRLPUK. + +Both parts of this puzzle are complete! They provide two gold stars: ** + +At this point, you should return to your Advent calendar and try another puzzle. + +If you still want to see it, you can get your puzzle input. + +You can also [Share] this puzzle.