Skip to content
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
Binary file added .DS_Store
Binary file not shown.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...`

<a href="https://youtu.be/ydH_B5KuqGs"><img src="http://i3.ytimg.com/vi/ydH_B5KuqGs/maxresdefault.jpg" style="height: 50%; width:50%;"/></a>

Expand Down
19 changes: 19 additions & 0 deletions Solución reto # 44 en Swift.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -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]))
4 changes: 4 additions & 0 deletions Solución reto # 44 en Swift.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>
Original file line number Diff line number Diff line change
Expand Up @@ -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..<numbers.count - 1).forEach { index in

let prev = numbers[index - 1]
let current = numbers[index]
let next = numbers[index + 1]

if prev == next && prev != current {
print("[\(prev), \(current), \(next)]")
boomerangs += 1
}
}

return boomerangs
}

print(numberOfBoomerangs(numbers: [2, 1, 2, 3, 3, 4, 2, 4]))
print(numberOfBoomerangs(numbers: [2, 1, 2, 1, 2]))
print(numberOfBoomerangs(numbers: [1, 2, 3, 4, 5]))
print(numberOfBoomerangs(numbers: [2, 2, 2, 2, 2]))
print(numberOfBoomerangs(numbers: [2, -2, 2, -2, 2]))
print(numberOfBoomerangs(numbers: [2, -2]))
print(numberOfBoomerangs(numbers: [2]))
print(numberOfBoomerangs(numbers: []))

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions WeeklyChallenge2022.playground/contents.xcplayground
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,5 @@
<page name='Challenge42'/>
<page name='Challenge43'/>
<page name='Challenge44'/>
<page name='Challenge45'/>
<page name='Challenge46'/>
</pages>
</playground>
35 changes: 35 additions & 0 deletions contenedor.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -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]))
4 changes: 4 additions & 0 deletions contenedor.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>