diff --git "a/Retos/Reto #14 - OCTAL Y HEXADECIMAL [F\303\241cil]/java/jorgenavarroenamoradotokio.java" "b/Retos/Reto #14 - OCTAL Y HEXADECIMAL [F\303\241cil]/java/jorgenavarroenamoradotokio.java" new file mode 100644 index 0000000000..a11535f56b --- /dev/null +++ "b/Retos/Reto #14 - OCTAL Y HEXADECIMAL [F\303\241cil]/java/jorgenavarroenamoradotokio.java" @@ -0,0 +1,43 @@ +package com.retos.ej14; + +public class jorgenavarroenamoradotokio { + + public static void main(String[] args) { + + System.out.println(decimalToOctal(255)); + System.out.println(decimalToHexadecimal(255)); + } + + private static String decimalToOctal(int numero) { + if (numero == 0) { + return "0"; + } + + StringBuilder octal = new StringBuilder(); + while (numero > 0) { + int remainder = numero % 8; + octal.insert(0, remainder); + numero /= 8; + } + + return octal.toString(); + } + + private static String decimalToHexadecimal(int decimal) { + if (decimal == 0) { + return "0"; + } + + StringBuilder hexadecimal = new StringBuilder(); + char[] hexChars = "0123456789ABCDEF".toCharArray(); // Caracteres hexadecimales + + while (decimal > 0) { + int remainder = decimal % 16; + hexadecimal.insert(0, hexChars[remainder]); // Insertar el carácter en la posición inicial + decimal /= 16; // Dividir el número decimal entre 16 + } + + return hexadecimal.toString(); + } + +} diff --git "a/Retos/Reto #15 - AUREBESH [F\303\241cil]/java/jorgenavarroenamoradotokio.java" "b/Retos/Reto #15 - AUREBESH [F\303\241cil]/java/jorgenavarroenamoradotokio.java" new file mode 100644 index 0000000000..21597e8d17 --- /dev/null +++ "b/Retos/Reto #15 - AUREBESH [F\303\241cil]/java/jorgenavarroenamoradotokio.java" @@ -0,0 +1,105 @@ +package com.retos.ej15; + +import java.text.Normalizer; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + +public class jorgenavarroenamoradotokio { + + private static final Map basic_alphabet = new HashMap<>(); + + static { + basic_alphabet.put("a", "aurek"); + basic_alphabet.put("b", "besh"); + basic_alphabet.put("c", "cresh"); + basic_alphabet.put("d", "dorn"); + basic_alphabet.put("e", "esk"); + basic_alphabet.put("f", "forn"); + basic_alphabet.put("g", "grek"); + basic_alphabet.put("h", "herf"); + basic_alphabet.put("i", "isk"); + basic_alphabet.put("j", "jenth"); + basic_alphabet.put("k", "krill"); + basic_alphabet.put("l", "leth"); + basic_alphabet.put("m", "merm"); + basic_alphabet.put("n", "nern"); + basic_alphabet.put("o", "osk"); + basic_alphabet.put("p", "peth"); + basic_alphabet.put("q", "qek"); + basic_alphabet.put("r", "resh"); + basic_alphabet.put("s", "senth"); + basic_alphabet.put("t", "trill"); + basic_alphabet.put("u", "usk"); + basic_alphabet.put("v", "vev"); + basic_alphabet.put("w", "wesk"); + basic_alphabet.put("x", "xesh"); + basic_alphabet.put("y", "yirt"); + basic_alphabet.put("z", "zerek"); + basic_alphabet.put("ae", "enth"); + basic_alphabet.put("eo", "onith"); + basic_alphabet.put("kh", "krenth"); + basic_alphabet.put("ng", "nen"); + basic_alphabet.put("oo", "orenth"); + basic_alphabet.put("sh", "sen"); + basic_alphabet.put("th", "thesh"); + } + + public static void main(String[] args) { + String frase = "Qué te ha parecido el reto? A mí me ha gustado mucho! Mañana sigue practicando."; + String aurebesh = idiomaToStarWars(frase); + + System.out.println(aurebesh); + System.out.println(starWarsToIdioma(aurebesh)); + + String frase2 = "The Mouredev"; + String aurebesh2 = idiomaToStarWars(frase2); + + System.out.println(aurebesh2); + System.out.println(starWarsToIdioma(aurebesh2)); + + } + + private static String idiomaToStarWars(String palabra) { + if (palabra == null || palabra.isEmpty()) + return ""; + + palabra = Normalizer.normalize(palabra, Normalizer.Form.NFD) + .replaceAll("\\p{InCombiningDiacriticalMarks}+", "") + .replaceAll("[.¡!¿?\"']", "") + .toLowerCase(Locale.ROOT); + + StringBuilder sb = new StringBuilder(); + String[] division = palabra.split(" "); + + for (String grupo : division) { + char[] caracteres = grupo.toLowerCase().toCharArray(); + for (char c : caracteres) { + String traduccion = basic_alphabet.get(String.valueOf(c)); + if (traduccion != null) + sb.append(traduccion); + } + sb.append(" "); + } + return sb.toString(); + } + + private static String starWarsToIdioma(String palabra) { + if (palabra == null || palabra.isEmpty()) + return ""; + + Map aurebeshAlphabet = new HashMap<>(); + for (Map.Entry entry : basic_alphabet.entrySet()) { + aurebeshAlphabet.put(entry.getValue(), entry.getKey()); + } + + StringBuilder translatedText = new StringBuilder(palabra); + for (Map.Entry entry : aurebeshAlphabet.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + translatedText = new StringBuilder(translatedText.toString().replace(key, value)); + } + + return translatedText.toString(); + } +} diff --git a/Retos/Reto #16 - LA ESCALERA [Media]/java/jorgenavarroenamoradotokio.java b/Retos/Reto #16 - LA ESCALERA [Media]/java/jorgenavarroenamoradotokio.java new file mode 100644 index 0000000000..d8c077f9ac --- /dev/null +++ b/Retos/Reto #16 - LA ESCALERA [Media]/java/jorgenavarroenamoradotokio.java @@ -0,0 +1,31 @@ +package com.retos.ej16; + +public class jorgenavarroenamoradotokio { + + public static void main(String[] args) { + drawStaircase(0); + drawStaircase(4); + drawStaircase(-4); + } + + public static void drawStaircase(int steps) { + if (steps > 0) { + // Escalera ascendente de izquierda a derecha + for (int step = 0; step <= steps; step++) { + String spaces = " ".repeat(steps - step); + String stepDraw = (step == 0) ? "_" : "_|"; + System.out.println(spaces + stepDraw); + } + } else if (steps < 0) { + // Escalera descendente de izquierda a derecha + for (int step = 0; step <= Math.abs(steps); step++) { + String spaces = " ".repeat((step * 2)); + String stepDraw = (step == 0) ? "_" : "|_"; + System.out.println(spaces + stepDraw); + } + } else { + System.out.println("__"); + } + } + +} diff --git "a/Retos/Reto #19 - AN\303\201LISIS DE TEXTO [Media]/java/jorgenavarroenamoradotokio.java" "b/Retos/Reto #19 - AN\303\201LISIS DE TEXTO [Media]/java/jorgenavarroenamoradotokio.java" new file mode 100644 index 0000000000..e5e5a50c13 --- /dev/null +++ "b/Retos/Reto #19 - AN\303\201LISIS DE TEXTO [Media]/java/jorgenavarroenamoradotokio.java" @@ -0,0 +1,48 @@ +package com.retos.ej19; + +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class jorgenavarroenamoradotokio { + + public static void main(String[] args) { + String texto = "Nos encontramos en un periodo de guerra civil. " + + "Las naves espaciales rebeldes, atacando desde una base oculta, " + + "han logrado su primera victoria contra el malvado Imperio Galáctico"; + + System.out.println(obtenerNumeroPalabras(texto)); + System.out.println(obtenerMediaLongitudPalabras(texto)); + System.out.println(obtenerNumeroOraciones(texto)); + System.out.println(obtenerPalabraMayorLongitud(texto)); + } + + private static long obtenerNumeroPalabras(String texto) { + return Stream.of(texto.split("\\s+")).filter(palabra -> !palabra.isEmpty()).count(); + } + + private static int obtenerMediaLongitudPalabras(String texto) { + List palabras = Arrays.stream(texto.split("\\s+")).filter(palabra -> !palabra.isEmpty()) + .collect(Collectors.toList()); + + int longitudTotal = palabras.stream().mapToInt(String::length).sum(); + + return palabras.isEmpty() ? 0 : (int) longitudTotal / palabras.size(); + } + + private static long obtenerNumeroOraciones(String texto) { + return Stream.of(texto.split("\\.")).filter(palabra -> !palabra.isEmpty()).count(); + } + + private static String obtenerPalabraMayorLongitud(String texto) { + List palabras = Arrays.stream(texto.split("\\s+")).filter(palabra -> !palabra.isEmpty()) + .collect(Collectors.toList()); + + Optional max = palabras.stream() + .max((palabra1, palabra2) -> Integer.compare(palabra1.length(), palabra2.length())); + + return max.orElse(""); + } +} diff --git a/Retos/Reto #20 - LA TRIFUERZA [Media]/java/jorgenavarroenamoradotokio.java b/Retos/Reto #20 - LA TRIFUERZA [Media]/java/jorgenavarroenamoradotokio.java new file mode 100644 index 0000000000..4a45a625a2 --- /dev/null +++ b/Retos/Reto #20 - LA TRIFUERZA [Media]/java/jorgenavarroenamoradotokio.java @@ -0,0 +1,25 @@ +package com.retos.ej20; + +public class jorgenavarroenamoradotokio { + + public static void main(String[] args) { + drawTriforce(2); + } + + public static void drawTriforce(int rows) { + for (int row = 0; row < rows * 2; row++) { + if (row < rows) { + String startSpace = " ".repeat(((2 * rows) - 1) - row); + String printRow = "*".repeat((2 * (row + 1)) - 1); + System.out.println(startSpace + printRow); + } else { + int currentRow = row - rows; + String startSpace = " ".repeat((rows - currentRow) - 1); + String middleSpace = " ".repeat((2 * (rows - currentRow)) - 1); + String printRow = "*".repeat((2 * (currentRow + 1)) - 1); + System.out.println(startSpace + printRow + middleSpace + printRow); + } + } + } + +} diff --git "a/Retos/Reto #21 - N\303\232MEROS PRIMOS GEMELOS [Media]/java/jorgenavarroenamoradotokio.java" "b/Retos/Reto #21 - N\303\232MEROS PRIMOS GEMELOS [Media]/java/jorgenavarroenamoradotokio.java" new file mode 100644 index 0000000000..7e3b0b7737 --- /dev/null +++ "b/Retos/Reto #21 - N\303\232MEROS PRIMOS GEMELOS [Media]/java/jorgenavarroenamoradotokio.java" @@ -0,0 +1,31 @@ +package com.retos.ej21; + +import java.util.stream.IntStream; + +public class jorgenavarroenamoradotokio { + + public static void main(String[] args) { + int rangoMaximo = 14; // Cambia este valor al rango máximo deseado + + System.out.println("Pares de números primos gemelos en el rango hasta " + rangoMaximo + ":"); + IntStream.rangeClosed(2, rangoMaximo - 2).filter(number -> isPrime(number) && isPrime(number + 2)) + .forEach(number -> System.out.println("(" + number + ", " + (number + 2) + ")")); + } + + public static boolean isPrime(int number) { + if (number <= 1) { + return false; + } + + if (number <= 3) { + return true; + } + + if (number % 2 == 0 || number % 3 == 0) { + return false; + } + + return IntStream.rangeClosed(5, (int) Math.sqrt(number)) + .allMatch(i -> number % i != 0 && number % (i + 2) != 0); + } +}