adventofcode/2016/day13/problem

89 lines
2.8 KiB
Plaintext
Raw Normal View History

2016-12-13 17:09:54 +00:00
Advent of Code
--- Day 13: A Maze of Twisty Little Cubicles ---
2018-03-15 16:24:23 +00:00
You arrive at the first floor of this new building to discover a much less
welcoming environment than the shiny atrium of the last one. Instead, you
are in a maze of twisty little cubicles, all alike.
2016-12-13 17:09:54 +00:00
2018-03-15 16:24:23 +00:00
Every location in this area is addressed by a pair of non-negative integers
(x,y). Each such coordinate is either a wall or an open space. You can't
move diagonally. The cube maze starts at 0,0 and seems to extend infinitely
toward positive x and y; negative values are invalid, as they represent a
location outside the building. You are in a small waiting area at 1,1.
2016-12-13 17:09:54 +00:00
2018-03-15 16:24:23 +00:00
While it seems chaotic, a nearby morale-boosting poster explains, the layout
is actually quite logical. You can determine whether a given x,y coordinate
will be a wall or an open space using a simple system:
2016-12-13 17:09:54 +00:00
 Find x*x + 3*x + 2*x*y + y + y*y.
2018-03-15 16:24:23 +00:00
2016-12-13 17:09:54 +00:00
 Add the office designer's favorite number (your puzzle input).
2018-03-15 16:24:23 +00:00
 Find the binary representation of that sum; count the number of bits
that are 1.
2016-12-13 17:09:54 +00:00
 If the number of bits that are 1 is even, it's an open space.
 If the number of bits that are 1 is odd, it's a wall.
2018-03-15 16:24:23 +00:00
For example, if the office designer's favorite number were 10, drawing walls
as # and open spaces as ., the corner of the building containing 0,0 would
look like this:
2016-12-13 17:09:54 +00:00
0123456789
0 .#.####.##
1 ..#..#...#
2 #....##...
3 ###.#.###.
4 .##..#..#.
5 ..##....#.
6 #...##.###
2018-03-15 16:24:23 +00:00
Now, suppose you wanted to reach 7,4. The shortest route you could take is
marked as O:
2016-12-13 17:09:54 +00:00
0123456789
0 .#.####.##
1 .O#..#...#
2 #OOO.##...
3 ###O#.###.
4 .##OO#OO#.
5 ..##OOO.#.
6 #...##.###
2018-03-15 16:24:23 +00:00
Thus, reaching 7,4 would take a minimum of 11 steps (starting from your
current location, 1,1).
2016-12-13 17:09:54 +00:00
What is the fewest number of steps required for you to reach 31,39?
2018-03-15 16:24:23 +00:00
Your puzzle answer was 86.
2016-12-13 17:09:54 +00:00
The first half of this puzzle is complete! It provides one gold star: *
--- Part Two ---
2018-03-15 16:24:23 +00:00
How many locations (distinct x,y coordinates, including your starting
location) can you reach in at most 50 steps?
2016-12-13 17:09:54 +00:00
Your puzzle input is still 1364.
2018-03-15 16:24:23 +00:00
Answer: 127
2016-12-13 17:09:54 +00:00
References
Visible links
. http://adventofcode.com/
. http://adventofcode.com/2016/about
. http://adventofcode.com/2016/support
. http://adventofcode.com/2016/events
. http://adventofcode.com/2016/settings
. http://adventofcode.com/2016/auth/logout
. http://adventofcode.com/2016
. http://adventofcode.com/2016
. http://adventofcode.com/2016/leaderboard
. http://adventofcode.com/2016/stats
. http://adventofcode.com/2016/sponsors
. http://adventofcode.com/2016/sponsors
. https://en.wikipedia.org/wiki/Binary_number
. https://en.wikipedia.org/wiki/Bit