diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..9075e18 Binary files /dev/null and b/.DS_Store differ diff --git a/README.md b/README.md index 83d6bc7..cf4efd8 100644 --- a/README.md +++ b/README.md @@ -77,9 +77,7 @@ Tienes toda la información extendida sobre los retos de programación semanales * **#42** - 17/10/22 - [`CONVERSOR DE TEMPERATURA`](https://github.com/mouredev/Weekly-Challenge-2022-Swift/blob/main/WeeklyChallenge2022.playground/Pages/Challenge42.xcplaygroundpage/Contents.swift) * **#43** - 24/10/22 - [`TRUCO O TRATO`](https://github.com/mouredev/Weekly-Challenge-2022-Swift/blob/main/WeeklyChallenge2022.playground/Pages/Challenge43.xcplaygroundpage/Contents.swift) * **#44** - 02/11/22 - [`BUMERANES`](https://github.com/mouredev/Weekly-Challenge-2022-Swift/blob/main/WeeklyChallenge2022.playground/Pages/Challenge44.xcplaygroundpage/Contents.swift) -* **#45** - 07/11/22 - [`CONTENEDOR DE AGUA`](https://github.com/mouredev/Weekly-Challenge-2022-Swift/blob/main/WeeklyChallenge2022.playground/Pages/Challenge45.xcplaygroundpage/Contents.swift) -* **#46** - 14/11/22 - [`¿DÓNDE ESTÁ EL ROBOT?`](https://github.com/mouredev/Weekly-Challenge-2022-Swift/blob/main/WeeklyChallenge2022.playground/Pages/Challenge46.xcplaygroundpage/Contents.swift) -* **#47** - 21/11/22 - `Publicación nuevo reto...` +* **#45** - 07/11/22 - `Publicación nuevo reto...` diff --git "a/Soluci\303\263n reto # 44 en Swift.playground/Contents.swift" "b/Soluci\303\263n reto # 44 en Swift.playground/Contents.swift" new file mode 100644 index 0000000..dda922b --- /dev/null +++ "b/Soluci\303\263n reto # 44 en Swift.playground/Contents.swift" @@ -0,0 +1,19 @@ +import Foundation + +func boumerang(array: [Int]) -> Int{ + var contBoumerang = 0 + + for i in 0...array.count - 3 { + let a = array[i] + let b = array[i+1] + let c = array[i+2] + if a != b && b != c && a == c { + print([a,b,c]) + contBoumerang += 1 + } + } + + return contBoumerang +} + +print(boumerang(array: [2, 1, 2, 3, 3, 4, 2, 4])) diff --git "a/Soluci\303\263n reto # 44 en Swift.playground/contents.xcplayground" "b/Soluci\303\263n reto # 44 en Swift.playground/contents.xcplayground" new file mode 100644 index 0000000..cf026f2 --- /dev/null +++ "b/Soluci\303\263n reto # 44 en Swift.playground/contents.xcplayground" @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/WeeklyChallenge2022.playground/Pages/Challenge44.xcplaygroundpage/Contents.swift b/WeeklyChallenge2022.playground/Pages/Challenge44.xcplaygroundpage/Contents.swift index 90b730b..8b0cd41 100644 --- a/WeeklyChallenge2022.playground/Pages/Challenge44.xcplaygroundpage/Contents.swift +++ b/WeeklyChallenge2022.playground/Pages/Challenge44.xcplaygroundpage/Contents.swift @@ -20,33 +20,3 @@ import Foundation * https://retosdeprogramacion.com/semanales2022. * */ - -func numberOfBoomerangs(numbers: [Int]) -> Int { - - if numbers.count < 3 { return 0 } - - var boomerangs = 0 - - (1.. Int { - - var units = 0 - var wall = 0 - var nextWall = 0 - - container.enumerated().forEach { (index, blocks) in - - if (blocks < 0) { - return - } - - if index != container.count - 1 && (index == 0 || nextWall == blocks) { - - wall = index == 0 ? blocks : nextWall - - nextWall = 0 - for nextBlocksIndex in index + 1 ..< container.count { - if container[nextBlocksIndex] >= nextWall { - nextWall = container[nextBlocksIndex] - } - } - } else { - let referenceWall = nextWall > wall ? wall : nextWall - let currentBlocks = referenceWall - blocks - units += currentBlocks >= 0 ? currentBlocks : 0 - } - } - - return units -} - -print(calculateWaterUnits(container: [4, 0, 3, 6])) -print(calculateWaterUnits(container: [4, 0, 3, 6, 1, 3])) -print(calculateWaterUnits(container: [5, 4, 3, 2, 1, 0])) -print(calculateWaterUnits(container: [0, 1, 2, 3, 4, 5])) -print(calculateWaterUnits(container: [4, 0, 3, 6, 1, 3, 0, 1, 6])) diff --git a/WeeklyChallenge2022.playground/Pages/Challenge46.xcplaygroundpage/Contents.swift b/WeeklyChallenge2022.playground/Pages/Challenge46.xcplaygroundpage/Contents.swift deleted file mode 100644 index e2b7cdd..0000000 --- a/WeeklyChallenge2022.playground/Pages/Challenge46.xcplaygroundpage/Contents.swift +++ /dev/null @@ -1,29 +0,0 @@ -import Foundation - -/* - * Reto #46 - * ¿DÓNDE ESTÁ EL ROBOT? - * Fecha publicación enunciado: 14/10/22 - * Fecha publicación resolución: 21/11/22 - * Dificultad: MEDIA - * - * Enunciado: Calcula dónde estará un robot (sus coordenadas finales) que se encuentra en una cudrícula - * representada por los ejes "x" e "y". - * - El robot comienza en la coordenada (0, 0). - * - Para idicarle que se mueva, le enviamos un array formado por enteros (positivos o negativos) - * que indican la secuencia de pasos a dar. - * - Por ejemplo: [10, 5, -2] indica que primero se mueve 10 pasos, se detiene, luego 5, se detiene, - * y finalmente 2. El resultado en este caso sería (x: -5, y: 12) - * - Si el número de pasos es negativo, se desplazaría en sentido contrario al que está mirando. - * - Los primeros pasos los hace en el eje "y". Interpretamos que está mirando hacia la parte - * positiva del eje "y". - * - El robot tiene un fallo en su programación: cada vez que finaliza una secuencia de pasos gira - * 90 grados en el sentido contrario a las agujas del reloj. - * - * Información adicional: - * - Usa el canal de nuestro Discord (https://mouredev.com/discord) "🔁reto-semanal" - * para preguntas, dudas o prestar ayuda a la comunidad. - * - Tienes toda la información sobre los retos semanales en - * https://retosdeprogramacion.com/semanales2022. - * - */ diff --git a/WeeklyChallenge2022.playground/contents.xcplayground b/WeeklyChallenge2022.playground/contents.xcplayground index 4e53c1d..0b390e1 100644 --- a/WeeklyChallenge2022.playground/contents.xcplayground +++ b/WeeklyChallenge2022.playground/contents.xcplayground @@ -47,7 +47,5 @@ - - \ No newline at end of file diff --git a/contenedor.playground/Contents.swift b/contenedor.playground/Contents.swift new file mode 100644 index 0000000..fc87b60 --- /dev/null +++ b/contenedor.playground/Contents.swift @@ -0,0 +1,35 @@ +import Foundation + +func contenedorAgua(arreglo:[Int])->Int{ + var inicio = 0 + var fin = arreglo.count - 1 + var suma = 0 + var dif: Int + + while inicio != fin { + let punteroMenor = arreglo[inicio] < arreglo[fin] ? inicio : fin + if punteroMenor == fin { + fin -= 1 + dif = arreglo[punteroMenor] - arreglo[fin] + while dif >= 0 { + suma += dif + fin -= 1 + dif = arreglo[punteroMenor] - arreglo[fin] + } + } else { + inicio += 1 + dif = arreglo[punteroMenor] - arreglo[inicio] + while dif >= 0 { + suma += dif + inicio += 1 + dif = arreglo[punteroMenor] - arreglo[inicio] + } + } + } + + return suma +} + +print(contenedorAgua(arreglo: [4, 0, 3, 6, 1, 3])) +print(contenedorAgua(arreglo: [4,2,5,6,3,2,3])) +print(contenedorAgua(arreglo: [4,0,6,2,3])) diff --git a/contenedor.playground/contents.xcplayground b/contenedor.playground/contents.xcplayground new file mode 100644 index 0000000..cf026f2 --- /dev/null +++ b/contenedor.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file