The error is that you are re-using the teleportation_start_position
variable.
teleportation_start_position = min(teleportation_start_position, teleportation_end_position);
Before this line the state of your program is:
teleportation_start_position
= 8teleportation_end_position
= 2
But after, it is:
teleportation_start_position
= 2teleportation_end_position
= 2
So in the next line you are doing:
teleportation_end_position = max(teleportation_start_position, teleportation_end_position);
// teleportation_end_position = max(2, 2);
2
solved C++ std::max acting like std::min