Last active
October 23, 2020 23:26
-
-
Save NiltonMorais/43ba456bd508027bf98ea0f5a1c7cbdd to your computer and use it in GitHub Desktop.
Teste Lógica - Ping Pong
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| saque("0:0"); // retorna "jogador a" | |
| saque("3:2"); // retorna "jogador b" | |
| saque("21:20"); // retorna "jogador a" | |
| saque("21:22"); // retorna "jogador b" | |
| saque("123321:2321232"); // um teste aleatório com um número bem grande | |
| function saque(string $placar): void { | |
| $pontuacao = explode(':', $placar); | |
| $totalSaques = intval($pontuacao[0]) + intval($pontuacao[1]); | |
| if($pontuacao[0] < 20 && $pontuacao[1] < 20) { | |
| if (($totalSaques/5)%2) { | |
| echo "jogador b\n"; | |
| } else { | |
| echo "jogador a\n"; | |
| } | |
| }else{ | |
| if (($totalSaques/2)%2) { | |
| echo "jogador b\n"; | |
| } else { | |
| echo "jogador a\n"; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment