diff --git a/WeeklyChallenge2022.playground/Pages/Challenge0.xcplaygroundpage/Contents.swift b/WeeklyChallenge2022.playground/Pages/Challenge0.xcplaygroundpage/Contents.swift index c0d2703..dc579e8 100644 --- a/WeeklyChallenge2022.playground/Pages/Challenge0.xcplaygroundpage/Contents.swift +++ b/WeeklyChallenge2022.playground/Pages/Challenge0.xcplaygroundpage/Contents.swift @@ -21,7 +21,13 @@ import Foundation */ for index in 1...100 { - let divisibleByThree = index % 3 == 0 - let divisibleByFive = index % 5 == 0 - print("\((divisibleByThree && divisibleByFive) ? "fizzbuzz" : (divisibleByThree ? "fizz" : (divisibleByFive ? "buzz" : index.description)))") + print(index % 3 == 0 && index % 5 == 0 ? "fizzbuzz" : index % 3 == 0 ? "fizz" : index % 5 == 0 ? "buzz" : "\(index)") } + +//Mouredev solution +// +//for index in 1...100 { +// let divisibleByThree = index % 3 == 0 +// let divisibleByFive = index % 5 == 0 +// print("\((divisibleByThree && divisibleByFive) ? "fizzbuzz" : (divisibleByThree ? "fizz" : (divisibleByFive ? "buzz" : index.description)))") +//} diff --git a/WeeklyChallenge2022.playground/Pages/Challenge1.xcplaygroundpage/Contents.swift b/WeeklyChallenge2022.playground/Pages/Challenge1.xcplaygroundpage/Contents.swift index d123250..51fcbc6 100644 --- a/WeeklyChallenge2022.playground/Pages/Challenge1.xcplaygroundpage/Contents.swift +++ b/WeeklyChallenge2022.playground/Pages/Challenge1.xcplaygroundpage/Contents.swift @@ -20,8 +20,29 @@ import Foundation * */ -func isAnagram(wordOne: String, wordTwo: String) -> Bool { - return wordOne.lowercased() == wordTwo.lowercased() ? false : wordOne.lowercased().sorted().elementsEqual(wordTwo.lowercased().sorted()) +func anagramTester (firstWord: String, secondWord: String) -> Bool { + var result: Bool = true +// Comprobamos que ambas palabras no son la misma, si no false + if firstWord.lowercased() == secondWord.lowercased() { + result = false + } else { + // Comprobamos que contienen las mismas letras, si no false + for character in firstWord.lowercased() { + if secondWord.lowercased().contains(character) == false { + result = false + } + } + } + print(result) + return result } -print(isAnagram(wordOne: "amor", wordTwo: "roma")) +anagramTester(firstWord: "Roma", secondWord: "amor") + +//Muuredev Solution +// +//func isAnagram(wordOne: String, wordTwo: String) -> Bool { +// return wordOne.lowercased() == wordTwo.lowercased() ? false : wordOne.lowercased().sorted().elementsEqual(wordTwo.lowercased().sorted()) +//} +// +//print(isAnagram(wordOne: "amor", wordTwo: "roma")) diff --git a/WeeklyChallenge2022.playground/Pages/Challenge2.xcplaygroundpage/Contents.swift b/WeeklyChallenge2022.playground/Pages/Challenge2.xcplaygroundpage/Contents.swift index 34a1893..d74d7f6 100644 --- a/WeeklyChallenge2022.playground/Pages/Challenge2.xcplaygroundpage/Contents.swift +++ b/WeeklyChallenge2022.playground/Pages/Challenge2.xcplaygroundpage/Contents.swift @@ -19,13 +19,26 @@ import Foundation * */ -var n0 = 0 -var n1 = 1 -(1...50).forEach { _ in - print(n0) - let fib = n0 + n1 - n0 = n1 - n1 = fib -} + + + + + + + + + +//Mouredev Solution +// +//var n0 = 0 +//var n1 = 1 +// +//(1...50).forEach { _ in +// print(n0) +// +// let fib = n0 + n1 +// n0 = n1 +// n1 = fib +//} diff --git a/WeeklyChallenge2022.playground/Pages/Challenge3.xcplaygroundpage/Contents.swift b/WeeklyChallenge2022.playground/Pages/Challenge3.xcplaygroundpage/Contents.swift index 054e0b3..aa8a901 100644 --- a/WeeklyChallenge2022.playground/Pages/Challenge3.xcplaygroundpage/Contents.swift +++ b/WeeklyChallenge2022.playground/Pages/Challenge3.xcplaygroundpage/Contents.swift @@ -18,23 +18,37 @@ import Foundation * */ -func isPrime(number: Int) -> Bool { - - if number < 2 { - return false - } - - for i in 2 ..< number { - if number % i == 0 { - return false - } - } - - return true -} - -(1...100).forEach { number in - if isPrime(number: number) { - print(number) - } -} + + + + + + + + + + + + +//Mouredev Solution +// +//func isPrime(number: Int) -> Bool { +// +// if number < 2 { +// return false +// } +// +// for i in 2 ..< number { +// if number % i == 0 { +// return false +// } +// } +// +// return true +//} +// +//(1...100).forEach { number in +// if isPrime(number: number) { +// print(number) +// } +//} diff --git a/WeeklyChallenge2022.playground/Pages/Challenge30.xcplaygroundpage/Contents.swift b/WeeklyChallenge2022.playground/Pages/Challenge30.xcplaygroundpage/Contents.swift index f7655da..17f23d4 100644 --- a/WeeklyChallenge2022.playground/Pages/Challenge30.xcplaygroundpage/Contents.swift +++ b/WeeklyChallenge2022.playground/Pages/Challenge30.xcplaygroundpage/Contents.swift @@ -25,3 +25,38 @@ import Foundation * - Subiré una posible solución al ejercicio el lunes siguiente al de su publicación. * */ + + +func asterisksTextBox(text: String) { + // Dividimos en un array de string cada palabra, haciendo la división por espacios + let textWordToWord = text.components(separatedBy: " ") + + // Calculamos el tamaño da cada palabra, las ordenamos de mayor a menor y nos quedamos con la mayor. + let longestWord = textWordToWord.map{$0.count}.sorted(by: >)[0] + 4 + + // Creamos la fila de asteriscos inicial y final. + var asterisksLine = "*" + while asterisksLine.count < longestWord { + asterisksLine += "*" + } + + // Dibujamos la primera fila de asteriscos. + print(asterisksLine) + + // Creamos el resto de filas. + for word in textWordToWord { + var wordText = word + // Rellenamos de espacios hasta que mida cada palabra un caracter más que la más larga, incluida ésta. + while wordText.count < longestWord - 3 { + wordText += " " + } + // Le añadimos el asterisco final + wordText += "*" + print("* \(wordText)") + } + + // Dibujamos la última fila de asteriscos. + print(asterisksLine) +} + + diff --git a/WeeklyChallenge2022.playground/Pages/Challenge31.xcplaygroundpage/Contents.swift b/WeeklyChallenge2022.playground/Pages/Challenge31.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..a360279 --- /dev/null +++ b/WeeklyChallenge2022.playground/Pages/Challenge31.xcplaygroundpage/Contents.swift @@ -0,0 +1,32 @@ +import Foundation + +/* + * Reto #31 + * AÑOS BISIESTOS + * Fecha publicación enunciado: 01/08/22 + * Fecha publicación resolución: 08/08/22 + * Dificultad: FÁCIL + * + * Enunciado: Crea una función que imprima los 30 próximos años bisiestos siguientes a uno dado. + * - Utiliza el menor número de líneas para resolver el ejercicio. + * + * Información adicional: + * - Usa el canal de nuestro discord (https://mouredev.com/discord) "🔁reto-semanal" para preguntas, dudas o prestar ayuda a la comunidad. + * - Puedes hacer un Fork del repo y una Pull Request al repo original para que veamos tu solución aportada. + * - Revisaré el ejercicio en directo desde Twitch el lunes siguiente al de su publicación. + * - Subiré una posible solución al ejercicio el lunes siguiente al de su publicación. + * + */ + + +func nextThirtyLeapYears (initialYear: Int) { + var leapYears: [Int] = [], yearConsult = initialYear + + while leapYears.count < 30 { + if (yearConsult % 4 == 0 && (yearConsult % 100 != 0 || yearConsult % 400 == 0)) { + leapYears.append(yearConsult) + } + yearConsult += 1 + } + print(leapYears) +}