day19: Day 19: A Series of Tubes

Description Usage Arguments Details Examples

Description

A Series of Tubes

Usage

1
2
3
4
5

Arguments

board

a board description

strings

a vector of strings describing a board

Details

Part One

Somehow, a network packet got lost and ended up here. It's trying to follow a routing diagram (your puzzle input), but it's confused about where to go.

Its starting point is just off the top of the diagram. Lines (drawn with |, -, and +) show the path it needs to take, starting by going down onto the only line connected to the top of the diagram. It needs to follow this path until it reaches the end (located somewhere within the diagram) and stop there.

Sometimes, the lines cross over each other; in these cases, it needs to continue going the same direction, and only turn left or right when there's no other option. In addition, someone has left letters on the line; these also don't change its direction, but it can use them to keep track of where it's been. For example:

1
2
3
4
5
6
     |
     |  +--+
     A  |  C
 F---|----E|--+
     |  |  |  D
     +B-+  +--+

Given this diagram, the packet needs to take the following path:

Following the path to the end, the letters it sees on its path are ABCDEF.

The little packet looks up at you, hoping you can help it find the way. What letters will it see (in the order it would see them) if it follows the path? (The routing diagram is very wide; make sure you view it without line wrapping.)

Part Two

The packet is curious how many steps it needs to go.

For example, using the same routing diagram from the example above...

1
2
3
4
5
6
     |
     |  +--+
     A  |  C
 F---|--|-E---+
     |  |  |  D
     +B-+  +--+

...the packet would go:

This would result in a total of 38 steps.

How many steps does the packet need to go?

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# The vector below has this grid line by line:
#     |
#     |  +--+
#     A  |  C
# F---|----E|--+
#     |  |  |  D
#     +B-+  +--+
grid <- c("    |", "    |  +--+", "    A  |  C", "F---|----E|--+",
          "    |  |  |  D", "    +B-+  +--+")

grid %>%
  create_board() %>%
  collect_board_letters() %>%
  paste0(collapse = "")

grid %>%
  create_board() %>%
  walk_board_from_start() %>%
  length()

tjmahr/adventofcode17 documentation built on May 30, 2019, 2:29 p.m.