day11: Day 11: Hex Ed

Description Usage Arguments Details Examples

Description

Hex Ed

Usage

1
2
3

Arguments

steps

a sequence of hexagon directions

Details

Part One

Crossing the bridge, you've barely reached the other side of the stream when a program comes up to you, clearly in distress. "It's my child process," she says, "he's gotten lost in an infinite grid!"

Fortunately for her, you have plenty of experience with infinite grids.

Unfortunately for you, it's a hex grid.

The hexagons ("hexes") in this grid are aligned such that adjacent hexes can be found to the north, northeast, southeast, south, southwest, and northwest:

1
2
3
4
5
6
7
  \ n  /
nw +--+ ne
  /    \
-+      +-
  \    /
sw +--+ se
  / s  \

You have the path the child process took. Starting where he started, you need to determine the fewest number of steps required to reach him. (A "step" means to move from the hex you are in to any adjacent hex.)

For example:

Part Two

How many steps away is the furthest he ever got from his starting position?

Examples

1
2
hexagon_distance(c("se", "sw", "se", "sw", "sw"))
find_longest_hexagon_distance(c("se", "sw", "se", "sw", "sw"))

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