Cup Stage

Cup Stage

The mission is in Blocked Mode. Access to the solutions is blocked for a day or two (even after you share your own), until we'll have enough solutions for you to check. All users who've solved the mission will get the notifications about their opening.

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,... .