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
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"formulahendry.code-runner"
]
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ Tienes toda la información extendida sobre los retos de programación semanales
* **#44** - 02/11/22 - [`BUMERANES`](https://github.com/mouredev/Weekly-Challenge-2022-Kotlin/blob/main/app/src/main/java/com/mouredev/weeklychallenge2022/Challenge44.kt)
* **#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)
* **#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)
* **#47** - 21/11/22 - `Publicación nuevo reto...`
* **#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)
* **#48** - 28/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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.mouredev.weeklychallenge2022
/*
* Reto #46
* ¿DÓNDE ESTÁ EL ROBOT?
* Fecha publicación enunciado: 14/10/22
* Fecha publicación enunciado: 14/11/22
* Fecha publicación resolución: 21/11/22
* Dificultad: MEDIA
*
Expand All @@ -28,3 +28,48 @@ package com.mouredev.weeklychallenge2022
*
*/

fun main() {
println(whereIsTheRobot(arrayOf(10, 5, -2)))
println(whereIsTheRobot(arrayOf(0, 0, 0)))
println(whereIsTheRobot(arrayOf()))
println(whereIsTheRobot(arrayOf(-10, -5, 2)))
println(whereIsTheRobot(arrayOf(-10, -5, 2, 4, -8)))
}

private enum class Direction {

POSITIVEY, NEGATIVEX, NEGATIVEY, POSITIVEX;

fun turn(): Direction {

return when (this) { POSITIVEY -> NEGATIVEX
NEGATIVEX -> NEGATIVEY
NEGATIVEY -> POSITIVEX
POSITIVEX -> POSITIVEY

}
}

}

private fun whereIsTheRobot(steps: Array<Int>): String {

var x = 0
var y = 0

var direction = Direction.POSITIVEY

steps.forEach { step ->

when (direction) {
Direction.POSITIVEY -> y += step
Direction.NEGATIVEX -> x -= step
Direction.NEGATIVEY -> y -= step
Direction.POSITIVEX -> x += step
}

direction = direction.turn()
}

return "x: $x, y: $y, direction: $direction"
}
103 changes: 103 additions & 0 deletions app/src/main/java/com/mouredev/weeklychallenge2022/Challenge47.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.mouredev.weeklychallenge2022

/*
* Reto #47
* VOCAL MÁS COMÚN
* Fecha publicación enunciado: 21/11/22
* Fecha publicación resolución: 28/11/22
* Dificultad: FÁCIL
*
* Enunciado: Crea un función que reciba un texto y retorne la vocal que más veces se repita.
* Si no hay vocales podrá devolver vacío.
*
* 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.
*
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;


namespace Vocales
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("ESTE PROGRAMA CUENTA LAS VOCALES Y CUANTAS VECES SE REPITEN:");
Console.WriteLine("************************************************************");
Console.WriteLine();
Console.WriteLine("INTRODUZZCA UN TEXTO CUALQUIERA:");

String texto = Console.ReadLine();
//Pasamos todos y cada uno de los caracteres a minusculas para que no haya problemas al controlar las vocales
texto = texto.ToLower();
Cuenta_vocales(texto);
}

static void Cuenta_vocales(String txt) {
int a = 0, e = 0, i = 0, o = 0, u = 0;

//Recorremos el texto en busca de las vocales y vamos sumando cuando encuentre cada vocal
for (int j = 0; j < txt.Length; j++){
if (txt[j] == 'a')
{
a += 1;
}else if (txt[j] == 'e')
{
e += 1;
}else if (txt[j] == 'i')
{
i += 1;
}else if(txt[j] == 'o')
{
o +=1;
}else if (txt[j] == 'u')
{
u += 1;
}
}

//Creamos dos listas, una con las vocales y otra con los valores de cada vocal encontrada
List<String> letras = new List<string>{ "a", "e", "i", "o", "u" };
List<int> valores = new List<int> { a, e, i, o, u };

int mayor = 0;
int m = 1;
String letra = "";

//ordenamos las listas de mayor a menor
for (int l=0; l < valores.Count - 1; l++)
{
if(valores[l] > valores[m])
{
mayor = valores[l];
letra = letras[l];
}
else
{
mayor = valores[m];
letra = letras[m];
valores[m] = valores[l];
letras[m] = letras[l];
valores[l] = mayor;
letras[l] = letra;
}
m += 1;
}

//Una vez ordenadas las dos listas, mostramos el valor de cada una en la posicion 0, ya que va a ser la letra que más veces se repite
Console.WriteLine("La letra que más se repite es: " + letras[0] + " con un total de: " + valores[0] + " veces.");

Console.ReadLine();
}
}
}