You are given a 1-D board game represented by its length board_length, a die with die_sides sides (rolling values 1 through die_sides), a starting position start, and a list of teleporters where each teleporter is a pair [source, destination].
A player rolls the die once from position start and moves forward by the rolled amount. If the player lands on a square that is the source of a teleporter, they are immediately transported to the teleporter's destination. The player cannot move beyond the last square on the board (positions are 0-indexed, so valid positions are 0 to board_length - 1).
Return the distinct positions the player can land on after one roll, sorted in ascending order.
Function Signature
def board_game_jump(board_length: int, die_sides: int, start: int, teleporters: list[list[int]]) -> list[int]:
Rules
-
A roll of
r
lands on square
start + r
. If
start + r >= board_length
, that roll is not a legal move and contributes no position. The player is not stopped on the last square.
-
Landing on a teleporter source moves the player to its destination, and the turn ends there. A destination may be ahead of or behind its source.
-
Teleporters do not chain, so at most one teleport happens per roll and a teleporter source never appears in the result.
-
Each square is the source of at most one teleporter.
-
Return each position once, sorted ascending. If no roll is legal, return an empty list.
Constraints
-
1 <= board_length <= 1000
-
1 <= die_sides <= 6
-
0 <= start < board_length
-
Every teleporter is a pair
[source, destination]
with
0 <= source, destination < board_length
-
No teleporter chains: a teleporter destination is never the source of another teleporter
Examples
Input: board_length = 10, die_sides = 6, start = 0, teleporters = [[3, 7], [5, 2]]
Output: [1, 2, 4, 6, 7]
Rolls 1 to 6 land on squares 1 to 6. Square 3 sends the player to 7 and square 5 sends them to 2, which a roll of 2 already reaches, so the distinct positions are 1, 2, 4, 6 and 7.
Input: board_length = 5, die_sides = 6, start = 3, teleporters = []
Output: [4]
A roll of 1 lands on square 4, the last square. Rolls 2 to 6 would reach squares 5 to 9, which are off the board.
Input: board_length = 8, die_sides = 3, start = 5, teleporters = [[6, 1], [7, 0]]
Output: [0, 1]
A roll of 1 lands on 6 and teleports back to 1, a roll of 2 lands on 7 and teleports to 0, and a roll of 3 would reach square 8, which does not exist.