Cup Stage

Cup Stage

Consider a world cup stage where players are competing in a knockout format: they face each other according to their positions in the bracket in a single-elimination match. The winners of each match advance to the next round until a champion is determined. Look at the example for 16 players.

example

Given two players' positions in the bracket and the total number of players, your program should determine what phase (final, 1/2, 1/4 etc.) they will face each other in, assuming they both win their matches until they meet.

Input: Three integers (int).

Output: String (str).

Examples:

assert cup_stage(10, 14, 16) == "1/2"
assert cup_stage(5, 18, 32) == "final"
assert cup_stage(5, 7, 8) == "1/2"
assert cup_stage(1, 2, 2) == "final"

Preconditions:

  • 1 <= pos1 < pos2 <= total;
  • total = 2n, n = 1, 2,... .