Home > Software design >  My test task for trainee. Javascript - quadratic equation and game theory
My test task for trainee. Javascript - quadratic equation and game theory

Time:09-17

I've been thinking that I found solution, but tests fail (I have no access to tests). The task: We want to organize a chess tournament.
One day - one game.
And as entry point we have number of days - that we can afford.

Tournament rules:
We have number of teams: if number is even - we divide number of teams by 2 and that's the number of games - so they fight 1 vs 1 in pairs, who lost is excluded from the competition.

For example : 20 teams => 10 games => 10 teams left.
And if the even number of teams left - we make the same iteration: divide by 2 into pairs.
10 teams - 5 games - 5 teams left. And now we have Odd number!

If we have odd number from start or get it in process - number of games is counted by another rule:

everyone needs to play with everyone. So the formula is = n * (n-1) / 2. For example 5 teams = 10 games. Or any odd number (to sum it all - if we have Odd number we always ignore first rule with pairs).

So: We have number of days and need to find all possible team numbers for this days, it can be more than one value, for example : 3 days, number of teams that is correct is 3 and 4;
Entry point 3, function logs 3 and 4;

If that's impossible to find teams - return -1;

1 ≤

  • Related