Skip to content

Reto semanal #31 #237

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)))")
//}
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Original file line number Diff line number Diff line change
Expand Up @@ -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
//}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}


Original file line number Diff line number Diff line change
@@ -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)
}