diff --git "a/Retos/Reto #47 - LA PALABRA DE 100 PUNTOS [F\303\241cil]/swift/didacdev.swift" "b/Retos/Reto #47 - LA PALABRA DE 100 PUNTOS [F\303\241cil]/swift/didacdev.swift" new file mode 100644 index 0000000000..f2ce6e60d2 --- /dev/null +++ "b/Retos/Reto #47 - LA PALABRA DE 100 PUNTOS [F\303\241cil]/swift/didacdev.swift" @@ -0,0 +1,45 @@ +import Foundation + +let alphabet = Array("abcdefghijklmnñopqrstuvwxyz") +var letterValues: [Character: Int] = [:] + +for (index, letter) in alphabet.enumerated() { + letterValues[letter] = index + 1 +} + +func getPoints(word: String) -> Int { + var points = 0 + + for letter in word { + if let number = letterValues[letter] { + points += number + } + } + + return points +} + +func play() { + var finish = false + + while !finish { + print() + print("Escribe una palabra:") + + if let word = readLine(){ + + let points = getPoints(word: word) + print() + print("Puntuación: \(points)") + + if points == 100 { + print("Has ganado!") + finish = true + } + } + } +} + +play() + +