Skip to main content
deleted 2106 characters in body
Source Link
Bubbler
  • 78.4k
  • 52
  • 61

AoCG2021 Day 6: Taxicab in a triangular cityAoCG2021 Day 6: Taxicab in a triangular city

Part of Advent of Code Golf 2021 event. See the linked meta post for details.

Related to AoC2016 Day 1, Part 1.


You're airdropped near Easter Bunny Headquarters in a city somewhere. "Near", unfortunately, is as close as you can get - the instructions on the Easter Bunny Recruiting Document the Elves intercepted start here, and nobody had time to work them out further.

The Document indicates that you should start at the given coordinates (where you just landed) and face North East. Then, follow the provided sequence: turn right 60 degrees, then walk forward the given number of blocks, ending at a new intersection.

"What, 60 degrees?" You think, and you look around. Then you realize the city is not quite like what you imagine; the streets in this city form a triangular grid.

Anyway, there's no time to follow such ridiculous instructions on foot, though, so you take a moment and work out the destination. Given that you can only walk on the street grid of the city, how far is the shortest path to the destination?

For example, if the instructions are [1, 1, 0, 2], it means to:

  • Turn right 60 degrees and move 1 block forward
  • Turn right 60 degrees and move 1 block forward
  • Turn right 60 degrees and stay in place
  • Turn right 60 degrees and move 2 blocks forward

In the end, you end up at just 1 block west of the start.

Input: A (possibly empty) list of non-negative integers. If you encounter a 0, it means to turn right 60 degrees but stay in place.

Output: A non-negative integer indicating how far away the destination is from the current position, measured in triangular taxicab distance.

Standard rules apply. The shortest code in bytes wins.

Test cases

[] -> 0
[1, 1, 1] -> 2
[1, 1, 0, 2] -> 1
[1, 2, 0, 0, 0, 2, 1] -> 4
[1, 2, 3, 4] -> 6

AoCG2021 Day 6: Taxicab in a triangular city

Part of Advent of Code Golf 2021 event. See the linked meta post for details.

Related to AoC2016 Day 1, Part 1.


You're airdropped near Easter Bunny Headquarters in a city somewhere. "Near", unfortunately, is as close as you can get - the instructions on the Easter Bunny Recruiting Document the Elves intercepted start here, and nobody had time to work them out further.

The Document indicates that you should start at the given coordinates (where you just landed) and face North East. Then, follow the provided sequence: turn right 60 degrees, then walk forward the given number of blocks, ending at a new intersection.

"What, 60 degrees?" You think, and you look around. Then you realize the city is not quite like what you imagine; the streets in this city form a triangular grid.

Anyway, there's no time to follow such ridiculous instructions on foot, though, so you take a moment and work out the destination. Given that you can only walk on the street grid of the city, how far is the shortest path to the destination?

For example, if the instructions are [1, 1, 0, 2], it means to:

  • Turn right 60 degrees and move 1 block forward
  • Turn right 60 degrees and move 1 block forward
  • Turn right 60 degrees and stay in place
  • Turn right 60 degrees and move 2 blocks forward

In the end, you end up at just 1 block west of the start.

Input: A (possibly empty) list of non-negative integers. If you encounter a 0, it means to turn right 60 degrees but stay in place.

Output: A non-negative integer indicating how far away the destination is from the current position, measured in triangular taxicab distance.

Standard rules apply. The shortest code in bytes wins.

Test cases

[] -> 0
[1, 1, 1] -> 2
[1, 1, 0, 2] -> 1
[1, 2, 0, 0, 0, 2, 1] -> 4
[1, 2, 3, 4] -> 6
added 142 characters in body
Source Link
Bubbler
  • 78.4k
  • 52
  • 61

AoCG2021 Day 6: Taxicab in a triangular city

Part of Advent of Code Golf 2021 event. See the linked meta post for details.

Related to AoC2016 Day 1, Part 1.


You're airdropped near Easter Bunny Headquarters in a city somewhere. "Near", unfortunately, is as close as you can get - the instructions on the Easter Bunny Recruiting Document the Elves intercepted start here, and nobody had time to work them out further.

The Document indicates that you should start at the given coordinates (where you just landed) and face North East. Then, follow the provided sequence: turn right 60 degrees, then walk forward the given number of blocks, ending at a new intersection.

"What, 60 degrees?" You think, and you look around. Then you realize the city is not quite like what you imagine; the streets in this city form a triangular grid.

Anyway, there's no time to follow such ridiculous instructions on foot, though, so you take a moment and work out the destination. Given that you can only walk on the street grid of the city, how far is the shortest path to the destination?

For example, if the instructions are [1, 1, 0, 2], it means to:

  • Turn right 60 degrees and move 1 block forward
  • Turn right 60 degrees and move 1 block forward
  • Turn right 60 degrees and stay in place
  • Turn right 60 degrees and move 2 blocks forward

In the end, you end up at just 1 block west of the start.

Input: A (possibly empty) list of non-negative integers. If you encounter a 0, it means to turn right 60 degrees but stay in place.

Output: A non-negative integer indicating how far away the destination is from the current position, measured in triangular taxicab distance.

Standard rules apply. The shortest code in bytes wins.

Test cases

[] -> 0
[1, 1, 1] -> 2
[1, 1, 0, 2] -> 1
[1, 2, 0, 0, 0, 2, 1] -> 4
[1, 2, 3, 4] -> 6

AoCG2021 Day 6: Taxicab in a triangular city

Related to AoC2016 Day 1, Part 1.


You're airdropped near Easter Bunny Headquarters in a city somewhere. "Near", unfortunately, is as close as you can get - the instructions on the Easter Bunny Recruiting Document the Elves intercepted start here, and nobody had time to work them out further.

The Document indicates that you should start at the given coordinates (where you just landed) and face North East. Then, follow the provided sequence: turn right 60 degrees, then walk forward the given number of blocks, ending at a new intersection.

"What, 60 degrees?" You think, and you look around. Then you realize the city is not quite like what you imagine; the streets in this city form a triangular grid.

Anyway, there's no time to follow such ridiculous instructions on foot, though, so you take a moment and work out the destination. Given that you can only walk on the street grid of the city, how far is the shortest path to the destination?

For example, if the instructions are [1, 1, 0, 2], it means to:

  • Turn right 60 degrees and move 1 block forward
  • Turn right 60 degrees and move 1 block forward
  • Turn right 60 degrees and stay in place
  • Turn right 60 degrees and move 2 blocks forward

In the end, you end up at just 1 block west of the start.

Input: A (possibly empty) list of non-negative integers. If you encounter a 0, it means to turn right 60 degrees but stay in place.

Output: A non-negative integer indicating how far away the destination is from the current position, measured in triangular taxicab distance.

Standard rules apply. The shortest code in bytes wins.

Test cases

[] -> 0
[1, 1, 1] -> 2
[1, 1, 0, 2] -> 1
[1, 2, 0, 0, 0, 2, 1] -> 4
[1, 2, 3, 4] -> 6

AoCG2021 Day 6: Taxicab in a triangular city

Part of Advent of Code Golf 2021 event. See the linked meta post for details.

Related to AoC2016 Day 1, Part 1.


You're airdropped near Easter Bunny Headquarters in a city somewhere. "Near", unfortunately, is as close as you can get - the instructions on the Easter Bunny Recruiting Document the Elves intercepted start here, and nobody had time to work them out further.

The Document indicates that you should start at the given coordinates (where you just landed) and face North East. Then, follow the provided sequence: turn right 60 degrees, then walk forward the given number of blocks, ending at a new intersection.

"What, 60 degrees?" You think, and you look around. Then you realize the city is not quite like what you imagine; the streets in this city form a triangular grid.

Anyway, there's no time to follow such ridiculous instructions on foot, though, so you take a moment and work out the destination. Given that you can only walk on the street grid of the city, how far is the shortest path to the destination?

For example, if the instructions are [1, 1, 0, 2], it means to:

  • Turn right 60 degrees and move 1 block forward
  • Turn right 60 degrees and move 1 block forward
  • Turn right 60 degrees and stay in place
  • Turn right 60 degrees and move 2 blocks forward

In the end, you end up at just 1 block west of the start.

Input: A (possibly empty) list of non-negative integers. If you encounter a 0, it means to turn right 60 degrees but stay in place.

Output: A non-negative integer indicating how far away the destination is from the current position, measured in triangular taxicab distance.

Standard rules apply. The shortest code in bytes wins.

Test cases

[] -> 0
[1, 1, 1] -> 2
[1, 1, 0, 2] -> 1
[1, 2, 0, 0, 0, 2, 1] -> 4
[1, 2, 3, 4] -> 6
Source Link
Bubbler
  • 78.4k
  • 52
  • 61

AoCG2021 Day 6: Taxicab in a triangular city

Related to AoC2016 Day 1, Part 1.


You're airdropped near Easter Bunny Headquarters in a city somewhere. "Near", unfortunately, is as close as you can get - the instructions on the Easter Bunny Recruiting Document the Elves intercepted start here, and nobody had time to work them out further.

The Document indicates that you should start at the given coordinates (where you just landed) and face North East. Then, follow the provided sequence: turn right 60 degrees, then walk forward the given number of blocks, ending at a new intersection.

"What, 60 degrees?" You think, and you look around. Then you realize the city is not quite like what you imagine; the streets in this city form a triangular grid.

Anyway, there's no time to follow such ridiculous instructions on foot, though, so you take a moment and work out the destination. Given that you can only walk on the street grid of the city, how far is the shortest path to the destination?

For example, if the instructions are [1, 1, 0, 2], it means to:

  • Turn right 60 degrees and move 1 block forward
  • Turn right 60 degrees and move 1 block forward
  • Turn right 60 degrees and stay in place
  • Turn right 60 degrees and move 2 blocks forward

In the end, you end up at just 1 block west of the start.

Input: A (possibly empty) list of non-negative integers. If you encounter a 0, it means to turn right 60 degrees but stay in place.

Output: A non-negative integer indicating how far away the destination is from the current position, measured in triangular taxicab distance.

Standard rules apply. The shortest code in bytes wins.

Test cases

[] -> 0
[1, 1, 1] -> 2
[1, 1, 0, 2] -> 1
[1, 2, 0, 0, 0, 2, 1] -> 4
[1, 2, 3, 4] -> 6