NewThe Learning module is now liveSee what's new

A board game, called "Thrilling Teleporters", consists of squares numbered from 0 to lastSquare. Some squares contain teleporters that instantly move a player to a new square. Each teleporter is described by a string "from,to", where landing on from moves the player to to, and each from is unique.

At the start of a turn, a player is on currentSquare. The player rolls a die with dieSides faces, numbered from 1 to dieSides. The turn proceeds as follows:

  • The player moves forward by the number shown on the die.
  • If this move would land at or past lastSquare, the player stops at lastSquare and does not activate any teleporter.
  • Otherwise, if the player lands on a square with a teleporter, they are instantly moved to that teleporter's destination. Only one teleporter can be activated per turn, even if the destination also contains a teleporter.
Test Cases
Input
Output
Expected