Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mouredev Kt code don't work correctly for duplicates and code block errors #6189

Open
Nitsua13 opened this issue Jan 3, 2024 · 1 comment

Comments

@Nitsua13
Copy link

Nitsua13 commented Jan 3, 2024

fun main() {
   println(playGames(arrayOf(Pair(Game.ROCK, Game.ROCK))))
   println(playGames(arrayOf(Pair(Game.ROCK, Game.SCISSORS))))
   println(playGames(arrayOf(Pair(Game.SCISSORS, Game.ROCK))))
   println(
           playGames(
                   arrayOf(
                           Pair(Game.ROCK, Game.ROCK),
                           Pair(Game.ROCK, Game.ROCK),
                           Pair(Game.ROCK, Game.ROCK),
                           Pair(Game.ROCK, Game.ROCK)
                   )
           )
   )
   println(
           playGames(
                   arrayOf(
                           Pair(Game.SPOCK, Game.ROCK),
                           Pair(Game.SCISSORS, Game.PAPER),
                           Pair(Game.ROCK, Game.ROCK),
                           Pair(Game.LIZARD, Game.SPOCK)
                   )
           )
   )
}

enum class Game {
   ROCK,
   PAPER,
   SCISSORS,
   LIZARD,
   SPOCK
}

fun playGames(games: Array<Pair<Game, Game>>): String {
   val rules: Map<Game, Array<Game>> =
           mapOf(
                   Game.ROCK to arrayOf(Game.SCISSORS, Game.LIZARD),
                   Game.PAPER to arrayOf(Game.ROCK, Game.SPOCK),
                   Game.SCISSORS to arrayOf(Game.PAPER, Game.LIZARD),
                   Game.LIZARD to arrayOf(Game.SPOCK, Game.PAPER),
                   Game.SPOCK to arrayOf(Game.ROCK, Game.SCISSORS)
           )

   var playerOne = 0
   var playerTwo = 0

   for (game in games) {
       if (game.first != game.second) {
           if (rules[game.first]?.contains(game.second) == true) {
               playerOne += 1
           } else {
               playerTwo += 1
           }
       }
   }

   return if (playerOne == playerTwo) "Tie"
   else if (playerOne > playerTwo) "Player 1" else "Player 2"
}

@Nitsua13
Copy link
Author

Nitsua13 commented Jan 3, 2024

@mouredev sorry for correct your code men, I love the content that you make. I'm web developer but I'llinspirate folow you chanel to become a Mobile developer because it's what I love. Thanks for this repo and the exercices 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant