Skip to content

Commit d78365f

Browse files
author
Jaime Fernández
committed
Jaimefere's solution mouredev#47
2 parents 58489b3 + e73ea65 commit d78365f

File tree

3 files changed

+84
-24
lines changed

3 files changed

+84
-24
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ Tienes toda la información extendida sobre los retos de programación semanales
7979
* **#44** - 02/11/22 - [`BUMERANES`](https://github.com/mouredev/Weekly-Challenge-2022-Kotlin/blob/main/app/src/main/java/com/mouredev/weeklychallenge2022/Challenge44.kt)
8080
* **#45** - 07/11/22 - [`CONTENEDOR DE AGUA`](https://github.com/mouredev/Weekly-Challenge-2022-Kotlin/blob/main/app/src/main/java/com/mouredev/weeklychallenge2022/Challenge45.kt)
8181
* **#46** - 14/11/22 - [`¿DÓNDE ESTÁ EL ROBOT?`](https://github.com/mouredev/Weekly-Challenge-2022-Kotlin/blob/main/app/src/main/java/com/mouredev/weeklychallenge2022/Challenge46.kt)
82-
* **#47** - 21/11/22 - `Publicación nuevo reto...`
82+
* **#47** - 21/11/22 - [`VOCAL MÁS COMÚN`](https://github.com/mouredev/Weekly-Challenge-2022-Kotlin/blob/main/app/src/main/java/com/mouredev/weeklychallenge2022/Challenge47.kt)
83+
* **#48** - 28/11/22 - `Publicación nuevo reto...`
8384

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

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

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.mouredev.weeklychallenge2022
33
/*
44
* Reto #46
55
* ¿DÓNDE ESTÁ EL ROBOT?
6-
* Fecha publicación enunciado: 14/10/22
6+
* Fecha publicación enunciado: 14/11/22
77
* Fecha publicación resolución: 21/11/22
88
* Dificultad: MEDIA
99
*
@@ -27,37 +27,49 @@ package com.mouredev.weeklychallenge2022
2727
* https://retosdeprogramacion.com/semanales2022.
2828
*
2929
*/
30+
31+
fun main() {
32+
println(whereIsTheRobot(arrayOf(10, 5, -2)))
33+
println(whereIsTheRobot(arrayOf(0, 0, 0)))
34+
println(whereIsTheRobot(arrayOf()))
35+
println(whereIsTheRobot(arrayOf(-10, -5, 2)))
36+
println(whereIsTheRobot(arrayOf(-10, -5, 2, 4, -8)))
37+
}
38+
3039
private enum class Direction {
31-
NORTH, WEST, SOUTH, EAST;
40+
41+
POSITIVEY, NEGATIVEX, NEGATIVEY, POSITIVEX;
3242

3343
fun turn(): Direction {
34-
return values()[(this.ordinal+1) % values().size]
35-
}
36-
}
3744

38-
private data class Coordinates(var x: Int, var y: Int) {
39-
override fun toString(): String {
40-
return "(x: $x, y: $y)"
45+
return when (this) { POSITIVEY -> NEGATIVEX
46+
NEGATIVEX -> NEGATIVEY
47+
NEGATIVEY -> POSITIVEX
48+
POSITIVEX -> POSITIVEY
49+
50+
}
4151
}
52+
4253
}
4354

44-
private fun moveRobot(moves: Array<Int>): Coordinates {
45-
var coordinates = Coordinates(0, 0)
46-
var direction = Direction.NORTH
55+
private fun whereIsTheRobot(steps: Array<Int>): String {
56+
57+
var x = 0
58+
var y = 0
59+
60+
var direction = Direction.POSITIVEY
4761

48-
moves.forEach { move ->
49-
when(direction) {
50-
Direction.NORTH -> coordinates.y += move
51-
Direction.WEST -> coordinates.x -= move
52-
Direction.SOUTH -> coordinates.y -= move
53-
Direction.EAST -> coordinates.x += move
62+
steps.forEach { step ->
63+
64+
when (direction) {
65+
Direction.POSITIVEY -> y += step
66+
Direction.NEGATIVEX -> x -= step
67+
Direction.NEGATIVEY -> y -= step
68+
Direction.POSITIVEX -> x += step
5469
}
70+
5571
direction = direction.turn()
5672
}
57-
return coordinates
58-
}
59-
60-
fun main() {
61-
println(moveRobot(arrayOf(10, 5, -2)))
62-
}
6373

74+
return "x: $x, y: $y, direction: $direction"
75+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.mouredev.weeklychallenge2022
2+
3+
import java.text.Normalizer
4+
5+
/*
6+
* Reto #47
7+
* VOCAL MÁS COMÚN
8+
* Fecha publicación enunciado: 21/11/22
9+
* Fecha publicación resolución: 28/11/22
10+
* Dificultad: FÁCIL
11+
*
12+
* Enunciado: Crea un función que reciba un texto y retorne la vocal que más veces se repita.
13+
* Si no hay vocales podrá devolver vacío.
14+
*
15+
* Información adicional:
16+
* - Usa el canal de nuestro Discord (https://mouredev.com/discord) "🔁reto-semanal"
17+
* para preguntas, dudas o prestar ayuda a la comunidad.
18+
* - Tienes toda la información sobre los retos semanales en
19+
* https://retosdeprogramacion.com/semanales2022.
20+
*
21+
*/
22+
private val REGEX_UNACCENTED = "\\p{InCombiningDiacriticalMarks}+".toRegex()
23+
24+
fun CharSequence.unaccented(): String {
25+
val temp = Normalizer.normalize(this, Normalizer.Form.NFD)
26+
return REGEX_UNACCENTED.replace(temp, "")
27+
}
28+
29+
fun getMostRepeatedVocals(text: String): String {
30+
val cleanedText = text.unaccented().lowercase()
31+
val vocalOccurrences: MutableMap<Char, Int> = mutableMapOf()
32+
cleanedText.forEach { letter ->
33+
if("aeiou".contains(letter)) {
34+
vocalOccurrences[letter] = vocalOccurrences[letter]?.plus(1) ?: 1
35+
}
36+
}
37+
val maxEntry = vocalOccurrences.maxByOrNull{ it.value }
38+
return if(maxEntry == null) "[]" else vocalOccurrences.filter{ it.value == maxEntry.value }.keys.toString()
39+
}
40+
41+
fun main() {
42+
println(getMostRepeatedVocals("¡Pssst!"))
43+
println(getMostRepeatedVocals("¡Hola Brais!"))
44+
println(getMostRepeatedVocals("¡Adiós Brais!"))
45+
println(getMostRepeatedVocals("¡Adiós Martín!"))
46+
}
47+

0 commit comments

Comments
 (0)