mouredev / retos-programacion-2023

Ejercicios de código semanales en 2023 de la comunidad MoureDev para practicar lógica en cualquier lenguaje de programación.
https://retosdeprogramacion.com/semanales2023
Apache License 2.0
5.12k stars 2.97k forks source link

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

Open Nitsua13 opened 8 months ago

Nitsua13 commented 8 months ago

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 commented 8 months ago

@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 🙂

imDarshanGK commented 3 days ago

from getpass import getpass username = input("Enter Username: ") password = getpass("Enter password: ")

print(password) If it shows the password, then use the print statement