Skip to content

Commit 97fed81

Browse files
committed
Resolución Reto #43 y enunciado Reto #44
1 parent b539548 commit 97fed81

File tree

6 files changed

+109
-4
lines changed

6 files changed

+109
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ Tienes toda la información extendida sobre los retos de programación semanales
7676
* **#41** - 10/10/22 - [`LA LEY DE OHM`](https://github.com/mouredev/Weekly-Challenge-2022-Kotlin/blob/main/app/src/main/java/com/mouredev/weeklychallenge2022/Challenge41.kt)
7777
* **#42** - 17/10/22 - [`CONVERSOR DE TEMPERATURA`](https://github.com/mouredev/Weekly-Challenge-2022-Kotlin/blob/main/app/src/main/java/com/mouredev/weeklychallenge2022/Challenge42.kt)
7878
* **#43** - 24/10/22 - [`TRUCO O TRATO`](https://github.com/mouredev/Weekly-Challenge-2022-Kotlin/blob/main/app/src/main/java/com/mouredev/weeklychallenge2022/Challenge43.kt)
79-
* **#44** - 02/11/22 - `Publicación nuevo reto...`
79+
* **#44** - 02/11/22 - [`BUMERANES`](https://github.com/mouredev/Weekly-Challenge-2022-Kotlin/blob/main/app/src/main/java/com/mouredev/weeklychallenge2022/Challenge44.kt)
80+
* **#45** - 07/11/22 - `Publicación nuevo reto...`
8081

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

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ android {
2929
kotlinOptions {
3030
jvmTarget = '1.8'
3131
}
32+
namespace 'com.mouredev.weeklychallenge2022'
3233
}
3334

3435
dependencies {

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.mouredev.weeklychallenge2022">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
43

54
<uses-permission android:name="android.permission.INTERNET" />
65

app/src/main/java/com/mouredev/weeklychallenge2022/Challenge43.kt

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,85 @@ package com.mouredev.weeklychallenge2022
3636
*
3737
*/
3838

39+
fun main() {
40+
println(trickOrTreat(Halloween.TRICK, arrayOf(
41+
Person("Brais", 35, 177),
42+
Person("Sara", 9, 122),
43+
Person("Pedro", 5, 80),
44+
Person("Roswell", 3, 54))))
45+
46+
println(trickOrTreat(Halloween.TREAT, arrayOf(
47+
Person("Brais", 35, 177),
48+
Person("Sara", 9, 122),
49+
Person("Pedro", 5, 80),
50+
Person("Roswell", 3, 54))))
51+
}
52+
53+
enum class Halloween {
54+
TRICK, TREAT
55+
}
56+
57+
data class Person(val name: String, val age: Int, val height: Int)
58+
59+
private fun trickOrTreat(halloween: Halloween, people: Array<Person>): String {
60+
61+
val scares = arrayOf("🎃", "👻", "💀", "🕷", "🕸", "🦇")
62+
val candies = arrayOf("🍰", "🍬", "🍡", "🍭", "🍪", "🍫", "🧁", "🍩")
63+
64+
var result = ""
65+
var height = 0
66+
67+
people.forEach { person ->
68+
69+
when (halloween) {
70+
Halloween.TRICK -> {
71+
72+
// Name
73+
(1 .. (person.name.replace(" ", "").length / 2)).forEach { _ ->
74+
result += scares.random()
75+
}
76+
77+
// Age
78+
if (person.age % 2 == 0) {
79+
result += scares.random()
80+
result += scares.random()
81+
}
82+
83+
// Height
84+
height += person.height
85+
while (height >= 100) {
86+
result += scares.random()
87+
result += scares.random()
88+
result += scares.random()
89+
height -= 100
90+
}
91+
92+
}
93+
Halloween.TREAT -> {
94+
95+
// Name
96+
(1 .. (person.name.replace(" ", "").length)).forEach { _ ->
97+
result += candies.random()
98+
}
99+
100+
// Age
101+
if (person.age <= 10) {
102+
(1 .. (person.age / 3)).forEach { _ ->
103+
result += candies.random()
104+
}
105+
}
106+
107+
// Height
108+
if (person.height <= 150) {
109+
(1 .. (person.height / 50)).forEach { _ ->
110+
result += candies.random()
111+
result += candies.random()
112+
}
113+
}
114+
}
115+
}
116+
117+
}
118+
119+
return result
120+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.mouredev.weeklychallenge2022
2+
3+
/*
4+
* Reto #44
5+
* BUMERANES
6+
* Fecha publicación enunciado: 02/10/22
7+
* Fecha publicación resolución: 07/11/22
8+
* Dificultad: FÁCIL
9+
*
10+
* Enunciado: Crea una función que retorne el número total de bumeranes de un array de números
11+
* enteros e imprima cada uno de ellos.
12+
* - Un bumerán (búmeran, boomerang) es una secuencia formada por 3 números seguidos, en el que el
13+
* primero y el último son iguales, y el segundo es diferente. Por ejemplo [2, 1, 2].
14+
* - En el array [2, 1, 2, 3, 3, 4, 2, 4] hay 2 bumeranes ([2, 1, 2] y [4, 2, 4]).
15+
*
16+
* Información adicional:
17+
* - Usa el canal de nuestro Discord (https://mouredev.com/discord) "🔁reto-semanal"
18+
* para preguntas, dudas o prestar ayuda a la comunidad.
19+
* - Tienes toda la información sobre los retos semanales en
20+
* https://retosdeprogramacion.com/semanales2022.
21+
*
22+
*/

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
mavenCentral()
66
}
77
dependencies {
8-
classpath "com.android.tools.build:gradle:7.0.4"
8+
classpath 'com.android.tools.build:gradle:7.3.1'
99
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
1010

1111
// NOTE: Do not place your application dependencies here; they belong

0 commit comments

Comments
 (0)