forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'mouredev:main' into main
- Loading branch information
Showing
5 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
Retos/Reto #1 - EL LENGUAJE HACKER [Fácil]/python/ShinMugenNoKabe.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Escribe un programa que reciba un texto y transforme lenguaje natural a | ||
# "lenguaje hacker" (conocido realmente como "leet" o "1337"). Este lenguaje | ||
# se caracteriza por sustituir caracteres alfanuméricos. | ||
# - Utiliza esta tabla (https://www.gamehouse.com/blog/leet-speak-cheat-sheet/) | ||
# con el alfabeto y los números en "leet". | ||
# (Usa la primera opción de cada transformación. Por ejemplo "4" para la "a") | ||
|
||
LEETCODE = { | ||
"a": "4", | ||
"b": "I3", | ||
"c": "[", | ||
"d": ")", | ||
"e": "3", | ||
"f": "|=", | ||
"g": "&", | ||
"h": "#", | ||
"i": "1", | ||
"j": ",_|", | ||
"k": ">|", | ||
"l": "1", | ||
"m": "/\/\\", | ||
"n": "^/", | ||
"o": "0", | ||
"p": "|*", | ||
"q": "(_,)", | ||
"r": "I2", | ||
"s": "5", | ||
"t": "7", | ||
"u": "(_)", | ||
"v": "\\/", | ||
"w": "\/\/", | ||
"x": "><", | ||
"y": "j", | ||
"z": "2" | ||
} | ||
|
||
|
||
def translate_to_leetcode(text: str) -> str: | ||
return "".join([LEETCODE.get(char.lower(), char) for char in text]) | ||
|
||
|
||
def main(): | ||
text = input(translate_to_leetcode("Escribe un texto: ")) | ||
print(translate_to_leetcode(text)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use std::collections::HashMap; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let url = "https://dog.ceo/api/breeds/image/random"; | ||
|
||
// Realizar la solicitud GET | ||
let response = reqwest::get(url) | ||
.await? | ||
.json::<HashMap<String, String>>() | ||
.await?; | ||
|
||
println!("{:#?}", response); | ||
|
||
Ok(()) | ||
} |
14 changes: 14 additions & 0 deletions
14
Retos/Reto #11 - URL PARAMS [Fácil]/python/ShinMugenNoKabe.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
def get_paramteres(url: str) -> list[str]: | ||
if not "?" in url: | ||
return [] | ||
|
||
query = url.split("?")[1] | ||
params = query.split("&") | ||
|
||
return [param.split("=")[1] for param in params] | ||
|
||
|
||
if __name__ == "__main__": | ||
result = get_paramteres("https://retosdeprogramacion.com?year=2023&challenge=0") | ||
assert result == ["2023", "0"] | ||
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
public class Countdown { | ||
|
||
public static void main(String[] args) { | ||
execute(10, 6); | ||
} | ||
|
||
public static void execute(int start, int seconds) { | ||
if (start > 0 && seconds > 0){ | ||
for (int i = start; i >= 0; i--) { | ||
System.out.println(i); | ||
if (i == 0) break; | ||
try{ | ||
Thread.sleep(seconds * 1000); | ||
} catch (Exception e){ | ||
System.out.println("There was an error: " + e.getMessage()); | ||
} | ||
} | ||
} else{ | ||
throw new RuntimeException("Los parámetros tienen que ser enteros positivos mayores a 0"); | ||
} | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
Retos/Reto #30 - EL TECLADO T9 [Media]/javascript/test0n3.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// Los primeros dispositivos móviles tenían un teclado llamado T9 | ||
// con el que se podía escribir texto utilizando únicamente su | ||
// teclado numérico (del 0 al 9). | ||
// | ||
// Crea una función que transforme las pulsaciones del T9 a su | ||
// representación con letras. | ||
// - Debes buscar cuál era su correspondencia original. | ||
// - Cada bloque de pulsaciones va separado por un guión. | ||
// - Si un bloque tiene más de un número, debe ser siempre el mismo. | ||
// - Ejemplo: | ||
// Entrada: 6-666-88-777-33-3-33-888 | ||
// Salida: MOUREDEV | ||
// | ||
|
||
const cellphoneDial = (input) => { | ||
const dial = { | ||
1: "1", | ||
2: "ABC2", | ||
3: "DEF3", | ||
4: "GHI4", | ||
5: "JKL5", | ||
6: "MNO6", | ||
7: "PQRS7", | ||
8: "TUV8", | ||
9: "WXYZ9", | ||
0: " 0", | ||
"*": "*", | ||
"#": "#", | ||
}; | ||
|
||
return input | ||
.split("-") | ||
.map((char) => { | ||
let char_pos = (char.length % dial[char[0]].length) - 1; | ||
return dial[char[0]].slice(char_pos)[0]; | ||
}) | ||
.join(""); | ||
}; | ||
|
||
const tests = { | ||
inputs: [ | ||
"6-666-88-777-33-3-33-888", | ||
"8-444-6-33-0-8-666-0-7777-555-33-33-7", | ||
"6-999-0-66-88-6-22-33-777-0-444-7777-0-99999-4444-77777-0-4444-2222-2222-0-3333-2222-4444", | ||
"6-99999999-0-8-33-777777777-8", | ||
], | ||
outputs: ["MOUREDEV", "TIME TO SLEEP", "MY NUMBER IS 947 422 324", "MY TEST"], | ||
}; | ||
|
||
let errors = 0; | ||
tests.inputs.forEach((input, index) => { | ||
const result = cellphoneDial(input); | ||
if (result != tests.outputs[index]) { | ||
errors += 1; | ||
console.log( | ||
`Error - input: ${input}, expected: ${tests.outputs[index]}, result: ${result}` | ||
); | ||
} | ||
}); | ||
console.log(`Errors: ${errors}`); |