Compare commits
64 Commits
7abcad7453
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 8671a962b4 | |||
| 695a1defaf | |||
| 000f8f72a2 | |||
| d9f4748095 | |||
| 40ceace587 | |||
| fd3dd1845e | |||
| 608531751c | |||
| e442e0e89f | |||
| 4507728150 | |||
| ce61363ec0 | |||
| 851f81a443 | |||
| df7aa7d898 | |||
| e64671f6a1 | |||
| 9c563d915c | |||
| 8c5c1c32a8 | |||
| f4800c58e8 | |||
| f311fc4dd1 | |||
| 0116149495 | |||
| 117cc87783 | |||
| 643fda700c | |||
| e5271ed247 | |||
| 05a39284f9 | |||
| b9e4b1f385 | |||
| 7d9450217c | |||
| ce7dd49028 | |||
| de1be634a3 | |||
| bc4795416a | |||
| a8445c6415 | |||
| 6ecf1e0e24 | |||
| eec80bdf24 | |||
| d60fd485e8 | |||
| db0cb83b84 | |||
| 10ed6c0c03 | |||
| cafb564382 | |||
| a73b6dc300 | |||
| 468e90ac55 | |||
| ad298b5e75 | |||
| 3ef50a1bac | |||
| 618c949452 | |||
| fbf3cad39a | |||
| 0cb757c9e4 | |||
| 119e10c2a0 | |||
| 140359f02d | |||
| 321e92f717 | |||
| 4af7058ed7 | |||
| 61e19478bd | |||
| 6e1cd4e0fc | |||
| 07d62f050e | |||
| d9437e766d | |||
| 7fe484d94e | |||
| 327e1279fc | |||
| a077149208 | |||
| bf9b2271d0 | |||
| c945ae68ec | |||
| b17ee402d6 | |||
| daa542bbe3 | |||
| cc25a4f8fd | |||
| 9d9c7e21bb | |||
| cc4a953382 | |||
| e61cdcb662 | |||
| 78e5f6f969 | |||
| d1942fcb3d | |||
| ece70a6f5e | |||
| 5969526dd1 |
@@ -1,6 +0,0 @@
|
|||||||
https://tinchicus.com/2022/09/26/rust-listado-del-curso-inicial/
|
|
||||||
|
|
||||||
- https://tinchicus.com/2022/06/01/rust-usando-a-cargo/ (hola_mundo)
|
|
||||||
- https://tinchicus.com/2022/06/03/rust-strings/ (cadenas)
|
|
||||||
- https://tinchicus.com/2022/06/06/rust-arrays/ (arreglos)
|
|
||||||
- https://tinchicus.com/2022/06/07/rust-vector/ (vectores)
|
|
||||||
7
arreglos/Cargo.lock
generated
7
arreglos/Cargo.lock
generated
@@ -1,7 +0,0 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
|
||||||
# It is not intended for manual editing.
|
|
||||||
version = 3
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "arreglos"
|
|
||||||
version = "0.1.0"
|
|
||||||
7
cadenas/Cargo.lock
generated
7
cadenas/Cargo.lock
generated
@@ -1,7 +0,0 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
|
||||||
# It is not intended for manual editing.
|
|
||||||
version = 3
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cadenas"
|
|
||||||
version = "0.1.0"
|
|
||||||
35
curso_tinchicusls/README.md
Normal file
35
curso_tinchicusls/README.md
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
## https://tinchicus.com/2022/09/26/rust-listado-del-curso-inicial/
|
||||||
|
|
||||||
|
- https://tinchicus.com/2022/06/01/rust-usando-a-cargo/ (hola_mundo)
|
||||||
|
- https://tinchicus.com/2022/06/03/rust-strings/ (cadenas)
|
||||||
|
- https://tinchicus.com/2022/06/06/rust-arrays/ (arreglos)
|
||||||
|
- https://tinchicus.com/2022/06/07/rust-vector/ (vectores)
|
||||||
|
- https://tinchicus.com/2022/06/08/rust-tuple/ (tupla)
|
||||||
|
- https://tinchicus.com/2022/06/09/rust-hash-map/ (mapeo)
|
||||||
|
- https://tinchicus.com/2022/06/10/rust-slice/ (slices)
|
||||||
|
- https://tinchicus.com/2022/06/13/rust-pasando-valores/ (porvalor y porreferencia)
|
||||||
|
- https://tinchicus.com/2022/06/14/rust-la-libreria-std/
|
||||||
|
- https://tinchicus.com/2022/06/15/rust-println/ (println)
|
||||||
|
- https://tinchicus.com/2022/06/16/rust-format/ (format)
|
||||||
|
- https://tinchicus.com/2022/06/17/rust-read_line/ (entrada)
|
||||||
|
- https://tinchicus.com/2022/06/20/rust-argumentos/ (argumento)
|
||||||
|
- https://tinchicus.com/2022/06/21/rust-for/ (bucles)
|
||||||
|
- https://tinchicus.com/2022/06/22/rust-if/ (condicion)
|
||||||
|
- https://tinchicus.com/2022/06/23/rust-match/ (coincidir)
|
||||||
|
- https://tinchicus.com/2022/06/24/rust-funciones-y-metodos/ (ejemplo01)
|
||||||
|
- https://tinchicus.com/2022/06/27/rust-closures/ (cierre)
|
||||||
|
- https://tinchicus.com/2022/06/28/rust-iteradores/ (iter)
|
||||||
|
- https://tinchicus.com/2022/06/29/rust-el-parametro-_/ (bucles2)
|
||||||
|
- https://tinchicus.com/2022/06/30/rust-loop-27/ (arreglos2)
|
||||||
|
- https://tinchicus.com/2022/07/01/rust-loop-labels/ (nombre)
|
||||||
|
- https://tinchicus.com/2022/07/04/rust-while/ (while)
|
||||||
|
- https://tinchicus.com/2022/07/05/rust-funciones-recursivas/ (recursiva)
|
||||||
|
- https://tinchicus.com/2022/07/06/rust-punto-y-coma/ (ejemplo02)
|
||||||
|
- https://tinchicus.com/2022/07/12/rust-memoria-estatica/ (ejemplo03)
|
||||||
|
- https://tinchicus.com/2022/07/13/rust-struct/ (estructura)
|
||||||
|
- https://tinchicus.com/2022/07/14/rust-struct-en-multiples-archivos/ (estructura2)
|
||||||
|
- https://tinchicus.com/2022/07/15/rust-tuple-struct/ (nuevotipo)
|
||||||
|
- https://tinchicus.com/2022/07/18/rust-enum/ (enums)
|
||||||
|
- https://tinchicus.com/2022/07/19/rust-patrones-y-coincidencias/ (iflet)
|
||||||
|
- https://tinchicus.com/2022/07/20/rust-ownership/ (prop)
|
||||||
|
- https://tinchicus.com/2022/07/21/rust-copy-trait/ (copiari32, copiar)
|
||||||
8
curso_tinchicusls/argumento/Cargo.toml
Normal file
8
curso_tinchicusls/argumento/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "argumento"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
12
curso_tinchicusls/argumento/src/main.rs
Normal file
12
curso_tinchicusls/argumento/src/main.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
use std::env;
|
||||||
|
|
||||||
|
// cargo run Huevos Pelotas Narices
|
||||||
|
fn main() {
|
||||||
|
let args: Vec<String> = env::args().collect();
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"Pasaste {:?} argumentos, ellos fueron {:?}",
|
||||||
|
args.len() - 1,
|
||||||
|
&args[1..]
|
||||||
|
);
|
||||||
|
}
|
||||||
8
curso_tinchicusls/arreglos2/Cargo.toml
Normal file
8
curso_tinchicusls/arreglos2/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "arreglos2"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
12
curso_tinchicusls/arreglos2/src/main.rs
Normal file
12
curso_tinchicusls/arreglos2/src/main.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
fn main() {
|
||||||
|
let mi_arreglo = ["Lovecraft", "Poe", "Barker", "King"];
|
||||||
|
let mut i = 0;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
if i >= mi_arreglo.len() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
println!("{}", mi_arreglo[i]);
|
||||||
|
i = i + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
8
curso_tinchicusls/bucles/Cargo.toml
Normal file
8
curso_tinchicusls/bucles/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "bucles"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
7
curso_tinchicusls/bucles/src/main.rs
Normal file
7
curso_tinchicusls/bucles/src/main.rs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
fn main() {
|
||||||
|
let mi_arreglo = ["Lovecraft", "Poe", "Barker", "King"];
|
||||||
|
|
||||||
|
for (pos, apellido) in mi_arreglo.iter().enumerate() {
|
||||||
|
println!("{} esta en la posicion {}", apellido, pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
8
curso_tinchicusls/bucles2/Cargo.toml
Normal file
8
curso_tinchicusls/bucles2/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "bucles2"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
8
curso_tinchicusls/bucles2/src/main.rs
Normal file
8
curso_tinchicusls/bucles2/src/main.rs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fn main() {
|
||||||
|
let mi_arreglo = ["Lovecraft", "Poe", "Barker", "King"];
|
||||||
|
|
||||||
|
// Evita avisos en el compilador y sirve para almacenar datos que no son necesarios
|
||||||
|
for (_, apellido) in mi_arreglo.iter().enumerate() {
|
||||||
|
println!("{}", apellido);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,13 +13,13 @@ fn string1() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn string2() {
|
fn string2() {
|
||||||
let mut renglon_final = String::new();
|
let mut _renglon_final = String::new();
|
||||||
|
|
||||||
let cadena1 = "Tinchicus.com";
|
let cadena1 = "Tinchicus.com";
|
||||||
let cadena2 = " es el ";
|
let cadena2 = " es el ";
|
||||||
let cadena3 = "mejor lugar para aprender";
|
let cadena3 = "mejor lugar para aprender";
|
||||||
|
|
||||||
renglon_final = format!("{}{}{}", cadena1, cadena2, cadena3);
|
_renglon_final = format!("{}{}{}", cadena1, cadena2, cadena3);
|
||||||
|
|
||||||
println!("{}", renglon_final);
|
println!("{}", _renglon_final);
|
||||||
}
|
}
|
||||||
8
curso_tinchicusls/cierre/Cargo.toml
Normal file
8
curso_tinchicusls/cierre/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "cierre"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
39
curso_tinchicusls/cierre/src/main.rs
Normal file
39
curso_tinchicusls/cierre/src/main.rs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
use std::thread;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
fn rutina_ejercicio(i: u32, a: u32) {
|
||||||
|
let cierre = |num| {
|
||||||
|
println!("Recalculando...");
|
||||||
|
thread::sleep(Duration::from_secs(2));
|
||||||
|
num
|
||||||
|
};
|
||||||
|
if i < 25 {
|
||||||
|
println!("Hoy haz {} sentadillas", cierre(i));
|
||||||
|
println!("Despues haz {} sentadillas", cierre(i));
|
||||||
|
} else {
|
||||||
|
if a == 3 {
|
||||||
|
println!("Descansa un poco y recuerda hidratarte");
|
||||||
|
} else {
|
||||||
|
println!("Hoy corre por {} minutos", cierre(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let valor_especificado = 27;
|
||||||
|
let numero_al_azar = 5;
|
||||||
|
|
||||||
|
rutina_ejercicio(valor_especificado, numero_al_azar);
|
||||||
|
|
||||||
|
// ejemplo creado por mi
|
||||||
|
|
||||||
|
let imprime_algo = |texto| {
|
||||||
|
println!("WTF!!!!!");
|
||||||
|
texto
|
||||||
|
};
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"Vamos a imprimir el texto....{}",
|
||||||
|
imprime_algo("Mis cojones mangas 3")
|
||||||
|
)
|
||||||
|
}
|
||||||
8
curso_tinchicusls/coincidir/Cargo.toml
Normal file
8
curso_tinchicusls/coincidir/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "coincidir"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
46
curso_tinchicusls/coincidir/src/main.rs
Normal file
46
curso_tinchicusls/coincidir/src/main.rs
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
fn main() {
|
||||||
|
let booleano = false;
|
||||||
|
|
||||||
|
let binario;
|
||||||
|
match booleano {
|
||||||
|
false => binario = 0,
|
||||||
|
true => binario = 1,
|
||||||
|
}
|
||||||
|
println!("{} -> {}", booleano, binario);
|
||||||
|
|
||||||
|
let booleano = !booleano;
|
||||||
|
let binario = match booleano {
|
||||||
|
false => 0,
|
||||||
|
true => 1,
|
||||||
|
};
|
||||||
|
println!("{} -> {}", booleano, binario);
|
||||||
|
|
||||||
|
let x = 1;
|
||||||
|
|
||||||
|
match x {
|
||||||
|
1 | 2 | 3 => println!("Works"),
|
||||||
|
_ => println!("Noooo"),
|
||||||
|
}
|
||||||
|
|
||||||
|
match x {
|
||||||
|
1..=10 => println!("Works to"),
|
||||||
|
_ => println!("Noooo"),
|
||||||
|
}
|
||||||
|
|
||||||
|
let y = 'G';
|
||||||
|
|
||||||
|
match y {
|
||||||
|
'A'..='Z' => println!("Works to"),
|
||||||
|
_ => println!("Noooo"),
|
||||||
|
}
|
||||||
|
|
||||||
|
match y {
|
||||||
|
p @ 'A'..='Z' => println!("{}", p),
|
||||||
|
_ => println!("Noo"),
|
||||||
|
}
|
||||||
|
|
||||||
|
match y {
|
||||||
|
p @ 'A'..='F' | p @ 'G'..='Z' => println!("{}", p),
|
||||||
|
_ => println!("Noo"),
|
||||||
|
}
|
||||||
|
}
|
||||||
8
curso_tinchicusls/condicion/Cargo.toml
Normal file
8
curso_tinchicusls/condicion/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "condicion"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
19
curso_tinchicusls/condicion/src/main.rs
Normal file
19
curso_tinchicusls/condicion/src/main.rs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
use std::io;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut entrada: String = String::new();
|
||||||
|
|
||||||
|
for _ in 0..3 {
|
||||||
|
io::stdin().read_line(&mut entrada).unwrap();
|
||||||
|
let n: i32 = entrada.trim().parse().unwrap();
|
||||||
|
|
||||||
|
if n < 0 {
|
||||||
|
println!("{} es negativo", n);
|
||||||
|
} else if n > 0 {
|
||||||
|
println!("{} es positivo", n);
|
||||||
|
} else {
|
||||||
|
println!("Es cero");
|
||||||
|
}
|
||||||
|
entrada.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
8
curso_tinchicusls/copiar/Cargo.toml
Normal file
8
curso_tinchicusls/copiar/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "copiar"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
12
curso_tinchicusls/copiar/src/main.rs
Normal file
12
curso_tinchicusls/copiar/src/main.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
fn sumar(v1: Vec<i32>, v2: Vec<i32>) -> (Vec<i32>, Vec<i32>, i32) {
|
||||||
|
let sum = v1.iter().fold(0i32, |a, &b| a + b);
|
||||||
|
let prod = v2.iter().fold(1i32, |a, &b| a * b);
|
||||||
|
return (v1, v2, sum + prod);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let vecuno = vec![2, 3, 5];
|
||||||
|
let vecdos = vec![3, 5];
|
||||||
|
let (vecuno, vecdos, rta) = sumar(vecuno, vecdos);
|
||||||
|
println!("{} + {} = {}", vecuno[0], vecdos[0], rta);
|
||||||
|
}
|
||||||
8
curso_tinchicusls/copiari32/Cargo.toml
Normal file
8
curso_tinchicusls/copiari32/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "copiari32"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
9
curso_tinchicusls/copiari32/src/main.rs
Normal file
9
curso_tinchicusls/copiari32/src/main.rs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fn incrementar(n: i32) -> i32 {
|
||||||
|
n + 32
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let num = 10i32;
|
||||||
|
let num2 = incrementar(num);
|
||||||
|
println!("num: {}, num2: {}", num, num2);
|
||||||
|
}
|
||||||
8
curso_tinchicusls/ejemplo01/Cargo.toml
Normal file
8
curso_tinchicusls/ejemplo01/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "ejemplo01"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
14
curso_tinchicusls/ejemplo01/src/main.rs
Normal file
14
curso_tinchicusls/ejemplo01/src/main.rs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
struct Perro {
|
||||||
|
peso: i32,
|
||||||
|
edad: i32,
|
||||||
|
}
|
||||||
|
impl Perro {
|
||||||
|
fn nuevo(a: i32, b: i32) -> Perro {
|
||||||
|
Perro { peso: a, edad: b }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let perro = Perro::nuevo(98, 87);
|
||||||
|
println!("{} {}", perro.edad, perro.peso);
|
||||||
|
}
|
||||||
8
curso_tinchicusls/ejemplo02/Cargo.toml
Normal file
8
curso_tinchicusls/ejemplo02/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "ejemplo02"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
22
curso_tinchicusls/ejemplo02/src/main.rs
Normal file
22
curso_tinchicusls/ejemplo02/src/main.rs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
fn main() {
|
||||||
|
let x = 5u32;
|
||||||
|
|
||||||
|
let y = {
|
||||||
|
let x_cuadrado = x * x;
|
||||||
|
let x_cubo = x_cuadrado * x;
|
||||||
|
x_cubo + x_cuadrado + x
|
||||||
|
};
|
||||||
|
|
||||||
|
// La variable z no tiene ningún valor, no es devuelto por el punto y coma
|
||||||
|
let z = {
|
||||||
|
2 * x;
|
||||||
|
};
|
||||||
|
|
||||||
|
// la variable h tiene el valor de 2*x por que es devuelta al no tener punto y coma.
|
||||||
|
let h = { 2 * x };
|
||||||
|
|
||||||
|
println!("x es {:?}", x);
|
||||||
|
println!("y es {:?}", y);
|
||||||
|
println!("z es {:?}", z);
|
||||||
|
println!("h es {:?}", h);
|
||||||
|
}
|
||||||
8
curso_tinchicusls/ejemplo03/Cargo.toml
Normal file
8
curso_tinchicusls/ejemplo03/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "ejemplo03"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
16
curso_tinchicusls/ejemplo03/src/main.rs
Normal file
16
curso_tinchicusls/ejemplo03/src/main.rs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
fn main() {
|
||||||
|
let x = 5u32;
|
||||||
|
|
||||||
|
let y: &u32;
|
||||||
|
{
|
||||||
|
let x_cuadrado = x * x;
|
||||||
|
let x_cubo = x_cuadrado * x;
|
||||||
|
// da un error por que la memoria es eliminada
|
||||||
|
// cuando es eliminado el scope
|
||||||
|
y = &(x_cubo + x_cuadrado + x);
|
||||||
|
};
|
||||||
|
|
||||||
|
let z = { 2 * x };
|
||||||
|
|
||||||
|
println!("x={}, y={}, z={}", z, y, z)
|
||||||
|
}
|
||||||
8
curso_tinchicusls/entrada/Cargo.toml
Normal file
8
curso_tinchicusls/entrada/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "entrada"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
30
curso_tinchicusls/entrada/src/main.rs
Normal file
30
curso_tinchicusls/entrada/src/main.rs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
use std::io;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let lector: io::Stdin = io::stdin();
|
||||||
|
let mut entrada: String = String::new();
|
||||||
|
|
||||||
|
// metodo 1 de manejar los errores
|
||||||
|
lector.read_line(&mut entrada).expect("Fallo lectura");
|
||||||
|
println!("Leido {}", entrada);
|
||||||
|
|
||||||
|
// metodo 2 de manejar los errores
|
||||||
|
let resultado: Result<usize, io::Error> = lector.read_line(&mut entrada);
|
||||||
|
|
||||||
|
if resultado.is_err() {
|
||||||
|
println!("Fallo el ingreso de datos");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Leido {}", entrada);
|
||||||
|
|
||||||
|
// metodo 3 de manejar los errores
|
||||||
|
let trimmed = entrada.trim();
|
||||||
|
let opcion: Option<i32> = trimmed.parse().ok();
|
||||||
|
|
||||||
|
match opcion {
|
||||||
|
// match equivale a switch de otros lenguajes
|
||||||
|
Some(i) => println!("Tu entero de la entrada: {}", i),
|
||||||
|
None => println!("Este no es un entero: {}", trimmed),
|
||||||
|
};
|
||||||
|
}
|
||||||
8
curso_tinchicusls/enums/Cargo.toml
Normal file
8
curso_tinchicusls/enums/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "enums"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
32
curso_tinchicusls/enums/src/main.rs
Normal file
32
curso_tinchicusls/enums/src/main.rs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
enum Numerado1 {
|
||||||
|
TipoTuple(f32, i32, String),
|
||||||
|
TipoStruct { var1: i32, var2: f32 },
|
||||||
|
StructTuple(i32),
|
||||||
|
Variable,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Numerado2 {
|
||||||
|
TipoTuple(f32, i32, String),
|
||||||
|
TipoStruct { var1: i32, var2: f32 },
|
||||||
|
StructTuple(i32),
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut texto1 = "".to_owned();
|
||||||
|
let mut texto2 = "".to_owned();
|
||||||
|
let mut num1 = 0f32;
|
||||||
|
|
||||||
|
let valor = Numerado1::TipoTuple(3.14, 1, "Hola".to_owned());
|
||||||
|
let valor2 = Numerado2::TipoTuple(3.14, 0, "Mundo".to_owned());
|
||||||
|
|
||||||
|
if let Numerado1::TipoTuple(f, i, s) = valor {
|
||||||
|
texto1 = s;
|
||||||
|
num1 = f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Numerado2::TipoTuple(f, i, s) = valor2 {
|
||||||
|
texto2 = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("{}, {}! del hombre {}", texto1, texto2, num1)
|
||||||
|
}
|
||||||
8
curso_tinchicusls/estructura/Cargo.toml
Normal file
8
curso_tinchicusls/estructura/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "estructura"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
65
curso_tinchicusls/estructura/src/main.rs
Normal file
65
curso_tinchicusls/estructura/src/main.rs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
struct Persona {
|
||||||
|
nombre: String,
|
||||||
|
edad: i32,
|
||||||
|
apellido: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Area {
|
||||||
|
oficina: String,
|
||||||
|
puesto: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Persona2 {
|
||||||
|
nombre: String,
|
||||||
|
edad: i32,
|
||||||
|
apellido: String,
|
||||||
|
area: Area,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// usuario1
|
||||||
|
let usuario = Persona {
|
||||||
|
nombre: String::from("Martín"),
|
||||||
|
apellido: String::from("Miranda"),
|
||||||
|
edad: 33,
|
||||||
|
};
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"{} {}, {} años",
|
||||||
|
usuario.nombre, usuario.apellido, usuario.edad
|
||||||
|
);
|
||||||
|
|
||||||
|
// usuario2
|
||||||
|
let mut usuario2 = Persona {
|
||||||
|
nombre: String::from("Federico"),
|
||||||
|
apellido: String::from("Caco"),
|
||||||
|
edad: 12,
|
||||||
|
};
|
||||||
|
|
||||||
|
// se puede cambiar por que usuario2 es mutable
|
||||||
|
usuario2.edad = 22;
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"{} {}, {} años",
|
||||||
|
usuario2.nombre, usuario2.apellido, usuario2.edad
|
||||||
|
);
|
||||||
|
|
||||||
|
// struct dentro de un struct
|
||||||
|
// usuario3
|
||||||
|
let mut usuario3 = Persona2 {
|
||||||
|
nombre: String::from("Lucas"),
|
||||||
|
apellido: String::from("Pelotas"),
|
||||||
|
edad: 76,
|
||||||
|
area: Area {
|
||||||
|
oficina: String::from("IT"),
|
||||||
|
puesto: String::from("Tecnico"),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
usuario3.edad = 45;
|
||||||
|
|
||||||
|
println!("Nombre: {}", usuario3.nombre);
|
||||||
|
println!("Apellido: {}", usuario3.apellido);
|
||||||
|
println!("Edad: {}", usuario3.edad);
|
||||||
|
println!("Oficina: {}", usuario3.area.oficina);
|
||||||
|
println!("Puesto: {}", usuario3.area.puesto);
|
||||||
|
}
|
||||||
8
curso_tinchicusls/estructura2/Cargo.toml
Normal file
8
curso_tinchicusls/estructura2/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "estructura2"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
47
curso_tinchicusls/estructura2/src/main.rs
Normal file
47
curso_tinchicusls/estructura2/src/main.rs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
mod persona;
|
||||||
|
use persona::*;
|
||||||
|
fn main() {
|
||||||
|
let usuario = Persona {
|
||||||
|
nombre: String::from("Martin"),
|
||||||
|
apellido: String::from("Miranda"),
|
||||||
|
edad: 45,
|
||||||
|
area: Area {
|
||||||
|
oficina: String::from("IT"),
|
||||||
|
puesto: String::from("Desarrollador"),
|
||||||
|
},
|
||||||
|
nomina: Nomina {
|
||||||
|
bruto: 100000,
|
||||||
|
neto: 50000,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("Nombre: {}", usuario.nombre);
|
||||||
|
println!("Apellido: {}", usuario.apellido);
|
||||||
|
println!("Edad: {}", usuario.edad);
|
||||||
|
println!("Oficina: {}", usuario.area.oficina);
|
||||||
|
println!("Puesto: {}", usuario.area.puesto);
|
||||||
|
println!("Bruto: {}", usuario.nomina.bruto);
|
||||||
|
println!("Neto: {}", usuario.nomina.neto);
|
||||||
|
|
||||||
|
let usuario2 = Persona {
|
||||||
|
nombre: String::from("Enzo"),
|
||||||
|
apellido: String::from("Tortore"),
|
||||||
|
edad: 33,
|
||||||
|
area: Area {
|
||||||
|
oficina: String::from("DB"),
|
||||||
|
puesto: String::from("Administrador"),
|
||||||
|
},
|
||||||
|
nomina: Nomina {
|
||||||
|
bruto: usuario.nomina.bruto,
|
||||||
|
neto: usuario.nomina.neto,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("Nombre: {}", usuario2.nombre);
|
||||||
|
println!("Apellido: {}", usuario2.apellido);
|
||||||
|
println!("Edad: {}", usuario2.edad);
|
||||||
|
println!("Oficina: {}", usuario2.area.oficina);
|
||||||
|
println!("Puesto: {}", usuario2.area.puesto);
|
||||||
|
println!("Bruto: {}", usuario2.nomina.bruto);
|
||||||
|
println!("Neto: {}", usuario2.nomina.neto);
|
||||||
|
}
|
||||||
4
curso_tinchicusls/estructura2/src/persona/area.rs
Normal file
4
curso_tinchicusls/estructura2/src/persona/area.rs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
pub struct Area {
|
||||||
|
pub oficina: String,
|
||||||
|
pub puesto: String,
|
||||||
|
}
|
||||||
12
curso_tinchicusls/estructura2/src/persona/mod.rs
Normal file
12
curso_tinchicusls/estructura2/src/persona/mod.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
pub mod area;
|
||||||
|
pub use area::*;
|
||||||
|
pub mod nomina;
|
||||||
|
pub use nomina::*;
|
||||||
|
|
||||||
|
pub struct Persona {
|
||||||
|
pub nombre: String,
|
||||||
|
pub edad: i32,
|
||||||
|
pub apellido: String,
|
||||||
|
pub area: Area,
|
||||||
|
pub nomina: Nomina,
|
||||||
|
}
|
||||||
4
curso_tinchicusls/estructura2/src/persona/nomina.rs
Normal file
4
curso_tinchicusls/estructura2/src/persona/nomina.rs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
pub struct Nomina {
|
||||||
|
pub bruto: i32,
|
||||||
|
pub neto: i32,
|
||||||
|
}
|
||||||
8
curso_tinchicusls/format/Cargo.toml
Normal file
8
curso_tinchicusls/format/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "format"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
23
curso_tinchicusls/format/src/main.rs
Normal file
23
curso_tinchicusls/format/src/main.rs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
fn main() {
|
||||||
|
println!("Hello, world!");
|
||||||
|
let mut visual = format!("{} {}", 23, 89);
|
||||||
|
println!("{}", visual);
|
||||||
|
visual = format!("{} {1} {} {0}", "Hola", "Mundo");
|
||||||
|
println!("{}", visual);
|
||||||
|
visual = format!("{t} {a} {b} {a}", a = "Hola", b = "Mundo", t = 23);
|
||||||
|
println!("{}", visual);
|
||||||
|
visual = format!("{:.4}", 3.1415927);
|
||||||
|
println!("{}", visual);
|
||||||
|
|
||||||
|
let v1 = format!("{:.3}", 3.1415927);
|
||||||
|
let v2 = format!("{:b}", 55);
|
||||||
|
let v3 = format!("{:+}!", 5);
|
||||||
|
let v4 = format!("{:x}", 95);
|
||||||
|
let v5 = format!("{:#x}", 95);
|
||||||
|
|
||||||
|
println!("{}", v1);
|
||||||
|
println!("{}", v2);
|
||||||
|
println!("{}", v3);
|
||||||
|
println!("{}", v4);
|
||||||
|
println!("{}", v5);
|
||||||
|
}
|
||||||
8
curso_tinchicusls/iflet/Cargo.toml
Normal file
8
curso_tinchicusls/iflet/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "iflet"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
14
curso_tinchicusls/iflet/src/main.rs
Normal file
14
curso_tinchicusls/iflet/src/main.rs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
fn main() {
|
||||||
|
let x = 1;
|
||||||
|
|
||||||
|
match x {
|
||||||
|
1 => println!("uno"),
|
||||||
|
_ => println!("no encontrado"),
|
||||||
|
}
|
||||||
|
|
||||||
|
if let 1 = x {
|
||||||
|
println!("uno")
|
||||||
|
} else {
|
||||||
|
println!("no encontrado")
|
||||||
|
}
|
||||||
|
}
|
||||||
8
curso_tinchicusls/iter/Cargo.toml
Normal file
8
curso_tinchicusls/iter/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "iter"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
17
curso_tinchicusls/iter/src/main.rs
Normal file
17
curso_tinchicusls/iter/src/main.rs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
fn main() {
|
||||||
|
let v1 = vec![1, 2, 3];
|
||||||
|
let v1_iter = v1.iter();
|
||||||
|
|
||||||
|
for val in v1_iter {
|
||||||
|
println!("{}", val);
|
||||||
|
}
|
||||||
|
|
||||||
|
let v2 = vec![50, 100, 200];
|
||||||
|
let v2_iter = v2.iter();
|
||||||
|
|
||||||
|
v2_iter.for_each(|e| print!("{}, ", e));
|
||||||
|
|
||||||
|
let mut v3 = vec![50, 100, 200];
|
||||||
|
v3.iter_mut().for_each(|e| *e += 23);
|
||||||
|
println!("{:?}", v3)
|
||||||
|
}
|
||||||
8
curso_tinchicusls/mapeo/Cargo.toml
Normal file
8
curso_tinchicusls/mapeo/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "mapeo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
77
curso_tinchicusls/mapeo/src/main.rs
Normal file
77
curso_tinchicusls/mapeo/src/main.rs
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("-- Ejercicio 1");
|
||||||
|
let mut mapa = HashMap::new();
|
||||||
|
|
||||||
|
mapa.insert('A', 10);
|
||||||
|
mapa.insert('B', 20);
|
||||||
|
|
||||||
|
let idx = 'A';
|
||||||
|
let mapeo = mapa.get(&idx);
|
||||||
|
println!("{:?}", mapeo);
|
||||||
|
|
||||||
|
println!("-- Ejercicio 2");
|
||||||
|
|
||||||
|
let mut mapa = HashMap::new();
|
||||||
|
|
||||||
|
mapa.insert(String::from("primero"), 10);
|
||||||
|
mapa.insert(String::from("segundo"), 20);
|
||||||
|
|
||||||
|
let idx = String::from("primero");
|
||||||
|
let mapeo = mapa.get(&idx);
|
||||||
|
println!("{:?}", mapeo);
|
||||||
|
|
||||||
|
println!("-- Ejercicio 3");
|
||||||
|
|
||||||
|
let mut mapa = HashMap::new();
|
||||||
|
|
||||||
|
mapa.insert(String::from("primero"), 10);
|
||||||
|
mapa.insert(String::from("segundo"), 20);
|
||||||
|
|
||||||
|
for (clave, valor) in &mapa {
|
||||||
|
println!("{}: {}", clave, valor);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("-- Ejercicio 4");
|
||||||
|
|
||||||
|
let mut mapa = HashMap::new();
|
||||||
|
|
||||||
|
mapa.insert(String::from("primero"), 10);
|
||||||
|
mapa.insert(String::from("segundo"), 20);
|
||||||
|
|
||||||
|
mapa.insert(String::from("primero"), 30);
|
||||||
|
|
||||||
|
for (clave, valor) in &mapa {
|
||||||
|
println!("{}: {}", clave, valor);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("-- Ejercicio 5");
|
||||||
|
|
||||||
|
let mut mapa = HashMap::new();
|
||||||
|
|
||||||
|
mapa.insert(String::from("primero"), 10);
|
||||||
|
mapa.insert(String::from("segundo"), 20);
|
||||||
|
|
||||||
|
mapa.entry(String::from("primero")).or_insert(30);
|
||||||
|
mapa.entry(String::from("tercero")).or_insert(40);
|
||||||
|
|
||||||
|
for (clave, valor) in &mapa {
|
||||||
|
println!("{}: {}", clave, valor);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("-- Ejercicio 6");
|
||||||
|
|
||||||
|
let texto = "hola mundo maravilloso mundo";
|
||||||
|
|
||||||
|
let mut mapa = HashMap::new();
|
||||||
|
|
||||||
|
for palabra in texto.split_whitespace() {
|
||||||
|
let contar = mapa.entry(palabra).or_insert(0);
|
||||||
|
*contar += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (clave, valor) in &mapa {
|
||||||
|
println!("{}: {}", clave, valor);
|
||||||
|
}
|
||||||
|
}
|
||||||
8
curso_tinchicusls/nombre/Cargo.toml
Normal file
8
curso_tinchicusls/nombre/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "nombre"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
13
curso_tinchicusls/nombre/src/main.rs
Normal file
13
curso_tinchicusls/nombre/src/main.rs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
fn main() {
|
||||||
|
'bucle_externo: for x in 0..10 {
|
||||||
|
'bucle_interno: for y in 0..10 {
|
||||||
|
if x % 2 == 0 {
|
||||||
|
continue 'bucle_externo;
|
||||||
|
}
|
||||||
|
if y % 2 != 0 {
|
||||||
|
continue 'bucle_interno;
|
||||||
|
}
|
||||||
|
println!("X: {}, Y: {}", x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
8
curso_tinchicusls/nuevotipo/Cargo.toml
Normal file
8
curso_tinchicusls/nuevotipo/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "nuevotipo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
11
curso_tinchicusls/nuevotipo/src/main.rs
Normal file
11
curso_tinchicusls/nuevotipo/src/main.rs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
// tuple-struct;
|
||||||
|
struct MiPi(f32);
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// creamos objeto del tipo MiPi
|
||||||
|
let mi_pi = MiPi(22f32 / 7f32);
|
||||||
|
println!("mi_pi = {:?}", mi_pi.0);
|
||||||
|
// asignación de patrón de tipo nuevo
|
||||||
|
let MiPi(pi) = mi_pi;
|
||||||
|
println!("pi = {}", pi);
|
||||||
|
}
|
||||||
8
curso_tinchicusls/porreferencia/Cargo.toml
Normal file
8
curso_tinchicusls/porreferencia/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "porreferencia"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
12
curso_tinchicusls/porreferencia/src/main.rs
Normal file
12
curso_tinchicusls/porreferencia/src/main.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
fn agregar(a: &i32, b: &i32) -> i32 {
|
||||||
|
//pide que los datos sean referencias
|
||||||
|
a + b
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let v1 = &3; // & referencia
|
||||||
|
let v2 = *v1; // * desreferencia
|
||||||
|
let valor = agregar(v1, &v2);
|
||||||
|
|
||||||
|
println!("{}", valor);
|
||||||
|
}
|
||||||
8
curso_tinchicusls/porvalor/Cargo.toml
Normal file
8
curso_tinchicusls/porvalor/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "porvalor"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
9
curso_tinchicusls/porvalor/src/main.rs
Normal file
9
curso_tinchicusls/porvalor/src/main.rs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fn agregar(a: i32, b: i32) -> i32 {
|
||||||
|
// como no tiene punto y coma este dato es retornado
|
||||||
|
a + b
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let valor = agregar(3, 5);
|
||||||
|
println!("{}", valor)
|
||||||
|
}
|
||||||
8
curso_tinchicusls/println/Cargo.toml
Normal file
8
curso_tinchicusls/println/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "println"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
10
curso_tinchicusls/println/src/main.rs
Normal file
10
curso_tinchicusls/println/src/main.rs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
fn main() {
|
||||||
|
println!("Hello, world!");
|
||||||
|
|
||||||
|
let v1 = " es el ";
|
||||||
|
let v2 = "lugar para ";
|
||||||
|
|
||||||
|
println!("tinchicus.com{}{}aprender", v1, v2);
|
||||||
|
|
||||||
|
println!("tinchicus.com{1}{0}aprender {0}", v1, v2);
|
||||||
|
}
|
||||||
8
curso_tinchicusls/prop/Cargo.toml
Normal file
8
curso_tinchicusls/prop/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "prop"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
9
curso_tinchicusls/prop/src/main.rs
Normal file
9
curso_tinchicusls/prop/src/main.rs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fn vec_transfer(v: Vec<i32>) {
|
||||||
|
println!("v[0] en la función = {}", v[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mivec = vec![1i32,2i32,3i32];
|
||||||
|
vec vec_transfer(mivec);
|
||||||
|
println!("mivec[0] es = {}", mivec[0]);
|
||||||
|
}
|
||||||
8
curso_tinchicusls/recursiva/Cargo.toml
Normal file
8
curso_tinchicusls/recursiva/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "recursiva"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
19
curso_tinchicusls/recursiva/src/main.rs
Normal file
19
curso_tinchicusls/recursiva/src/main.rs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
fn recursivo(n: i32) {
|
||||||
|
let mut _v: i32 = 0;
|
||||||
|
|
||||||
|
if n % 2 == 0 {
|
||||||
|
_v = n / 2;
|
||||||
|
} else {
|
||||||
|
_v = 3 * n + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("{}", _v);
|
||||||
|
|
||||||
|
if _v != 1 {
|
||||||
|
recursivo(_v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
recursivo(12)
|
||||||
|
}
|
||||||
8
curso_tinchicusls/slices/Cargo.toml
Normal file
8
curso_tinchicusls/slices/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "slices"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
16
curso_tinchicusls/slices/src/main.rs
Normal file
16
curso_tinchicusls/slices/src/main.rs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
fn primera_palabra(s: &String) -> usize {
|
||||||
|
let b = s.as_bytes();
|
||||||
|
for (i, &item) in b.iter().enumerate() {
|
||||||
|
if item == b' ' {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s.len()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let s = String::from("Hola Mundo Cruel");
|
||||||
|
let pos = primera_palabra(&s);
|
||||||
|
let palabra = &s[0..pos];
|
||||||
|
println!("{}", palabra);
|
||||||
|
}
|
||||||
8
curso_tinchicusls/tuplas/Cargo.toml
Normal file
8
curso_tinchicusls/tuplas/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "tuplas"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
28
curso_tinchicusls/tuplas/src/main.rs
Normal file
28
curso_tinchicusls/tuplas/src/main.rs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
fn main() {
|
||||||
|
let (uno, dos, tres) = (1, 2, 3);
|
||||||
|
|
||||||
|
println!("Uno = {}", uno);
|
||||||
|
println!("Dos = {}", dos);
|
||||||
|
println!("Tres = {}", tres);
|
||||||
|
|
||||||
|
let tup = (3, "foo");
|
||||||
|
|
||||||
|
println!("{}", tup.0);
|
||||||
|
|
||||||
|
let tup: (i32, &str) = (3, "foo");
|
||||||
|
|
||||||
|
println!("{}", tup.0);
|
||||||
|
|
||||||
|
let mut _cambiar = (1.1f32, 1);
|
||||||
|
let aesto = (3.14f32, 6);
|
||||||
|
_cambiar = aesto;
|
||||||
|
|
||||||
|
println!("{}", aesto.0);
|
||||||
|
|
||||||
|
/* No funciona porque el tipo de dato no está en el mismo orden
|
||||||
|
|
||||||
|
let mut cambiar = (1.1f32, 1);
|
||||||
|
let aesto = (6, 3.14f32);
|
||||||
|
cambiar = aesto;
|
||||||
|
*/
|
||||||
|
}
|
||||||
8
curso_tinchicusls/vectores/Cargo.toml
Normal file
8
curso_tinchicusls/vectores/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "vectores"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
15
curso_tinchicusls/vectores/src/main.rs
Normal file
15
curso_tinchicusls/vectores/src/main.rs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
// se diferencia de los arrays en que se puede modificar el tamaño
|
||||||
|
fn main() {
|
||||||
|
// definición más explícita
|
||||||
|
let mut _mi_vector: Vec<i32> = Vec::new();
|
||||||
|
// otra forma expecificando el tipo
|
||||||
|
let mut _mi_vector2 = vec![4i32, 2, 4, 8, 16];
|
||||||
|
// otra forma
|
||||||
|
let mut _mi_vector3 = [2, 4, 8, 16];
|
||||||
|
// solo definimos el tamaño
|
||||||
|
let mut _mi_vector4: Vec<i64> = Vec::with_capacity(30);
|
||||||
|
// con un iterador
|
||||||
|
let _mi_vector5: Vec<u64> = (0..10).collect();
|
||||||
|
|
||||||
|
println!("{}", _mi_vector5[7])
|
||||||
|
}
|
||||||
8
curso_tinchicusls/whileloop/Cargo.toml
Normal file
8
curso_tinchicusls/whileloop/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "whileloop"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
9
curso_tinchicusls/whileloop/src/main.rs
Normal file
9
curso_tinchicusls/whileloop/src/main.rs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fn main() {
|
||||||
|
let mi_arreglo = ["Lovecraft", "Poe", "Barker", "King"];
|
||||||
|
let mut i = 0;
|
||||||
|
|
||||||
|
while i < mi_arreglo.len() {
|
||||||
|
println!("{}", mi_arreglo[i]);
|
||||||
|
i = i + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
3
ejercicios/README.md
Normal file
3
ejercicios/README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Ejercicios de:
|
||||||
|
|
||||||
|
### https://github.com/mouredev/retos-programacion-2023
|
||||||
8
ejercicios/reto00/Cargo.toml
Normal file
8
ejercicios/reto00/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "reto00"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
22
ejercicios/reto00/src/main.rs
Normal file
22
ejercicios/reto00/src/main.rs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Escribe un programa que muestre por consola (con un print) los
|
||||||
|
* números de 1 a 100 (ambos incluidos y con un salto de línea entre
|
||||||
|
* cada impresión), sustituyendo los siguientes:
|
||||||
|
* - Múltiplos de 3 por la palabra "fizz".
|
||||||
|
* - Múltiplos de 5 por la palabra "buzz".
|
||||||
|
* - Múltiplos de 3 y de 5 a la vez por la palabra "fizzbuzz".
|
||||||
|
*/
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
for num in 1..101 {
|
||||||
|
let mut texto = num.to_string();
|
||||||
|
if num % 3 == 0 && num % 5 == 0 {
|
||||||
|
texto = String::from("fizzbuzz")
|
||||||
|
} else if num % 3 == 0 {
|
||||||
|
texto = String::from("fizz")
|
||||||
|
} else if num % 5 == 0 {
|
||||||
|
texto = String::from("buzz")
|
||||||
|
}
|
||||||
|
println!("{}", texto)
|
||||||
|
}
|
||||||
|
}
|
||||||
8
ejercicios/reto01/Cargo.toml
Normal file
8
ejercicios/reto01/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "reto01"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
60
ejercicios/reto01/src/main.rs
Normal file
60
ejercicios/reto01/src/main.rs
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* 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")
|
||||||
|
*/
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let alphabet = String::from_utf8((b'A'..=b'Z').chain(b'0'..=b'9').collect()).unwrap();
|
||||||
|
println!("{}", alphabet);
|
||||||
|
let respuesta = [
|
||||||
|
"4",
|
||||||
|
"l3",
|
||||||
|
"[",
|
||||||
|
")",
|
||||||
|
"3",
|
||||||
|
"|=",
|
||||||
|
"&",
|
||||||
|
"#",
|
||||||
|
"1",
|
||||||
|
",_|",
|
||||||
|
">|",
|
||||||
|
"1",
|
||||||
|
"^^",
|
||||||
|
"^",
|
||||||
|
"0",
|
||||||
|
"|*",
|
||||||
|
"(_,)",
|
||||||
|
"l2",
|
||||||
|
"hu",
|
||||||
|
"gg",
|
||||||
|
"pesadooooooooo",
|
||||||
|
"0",
|
||||||
|
"yy",
|
||||||
|
"2",
|
||||||
|
"3",
|
||||||
|
"4",
|
||||||
|
];
|
||||||
|
let vecalphabet: Vec<_> = alphabet.split("").collect();
|
||||||
|
let texto = String::from("wtf hijo de puta hay que decirlo mas").to_uppercase();
|
||||||
|
let vectexto: Vec<_> = texto.split("").collect();
|
||||||
|
let mut textfinal = "".to_string();
|
||||||
|
for item in vectexto {
|
||||||
|
if alphabet.contains(item) {
|
||||||
|
let index = vecalphabet
|
||||||
|
.iter()
|
||||||
|
.position(|&r| r == item.to_string())
|
||||||
|
.unwrap();
|
||||||
|
if index != 0 {
|
||||||
|
//println!("es->{}", respuesta[index]);
|
||||||
|
textfinal += &respuesta[index].to_string();
|
||||||
|
}
|
||||||
|
} else if item == " ".to_string() {
|
||||||
|
textfinal += &" ".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!("{}", textfinal)
|
||||||
|
}
|
||||||
8
ejercicios/reto02/Cargo.toml
Normal file
8
ejercicios/reto02/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "reto03"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
57
ejercicios/reto02/src/main.rs
Normal file
57
ejercicios/reto02/src/main.rs
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Escribe un programa que muestre cómo transcurre un juego de tenis y quién lo ha ganado.
|
||||||
|
* El programa recibirá una secuencia formada por "P1" (Player 1) o "P2" (Player 2), según quien
|
||||||
|
* gane cada punto del juego.
|
||||||
|
*
|
||||||
|
* - Las puntuaciones de un juego son "Love" (cero), 15, 30, 40, "Deuce" (empate), ventaja.
|
||||||
|
* - Ante la secuencia [P1, P1, P2, P2, P1, P2, P1, P1], el programa mostraría lo siguiente:
|
||||||
|
* 15 - Love
|
||||||
|
* 30 - Love
|
||||||
|
* 30 - 15
|
||||||
|
* 30 - 30
|
||||||
|
* 40 - 30
|
||||||
|
* Deuce
|
||||||
|
* Ventaja P1
|
||||||
|
* Ha ganado el P1
|
||||||
|
* - Si quieres, puedes controlar errores en la entrada de datos.
|
||||||
|
* - Consulta las reglas del juego si tienes dudas sobre el sistema de puntos.
|
||||||
|
*/
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let secuencia = vec!["P1", "P1", "P2", "P2", "P1", "P2", "P1", "P1"];
|
||||||
|
let puntos = vec!["Love", "15", "30", "40"];
|
||||||
|
let mut jugador1 = 0;
|
||||||
|
let mut jugador2 = 0;
|
||||||
|
let mut puntos1;
|
||||||
|
let mut puntos2;
|
||||||
|
for ele in secuencia {
|
||||||
|
if ele == "P1" {
|
||||||
|
jugador1 += 1;
|
||||||
|
} else if ele == "P2" {
|
||||||
|
jugador2 += 1;
|
||||||
|
}
|
||||||
|
if jugador1 < puntos.len() {
|
||||||
|
puntos1 = puntos[jugador1].to_string();
|
||||||
|
} else {
|
||||||
|
puntos1 = "+".to_string();
|
||||||
|
}
|
||||||
|
puntos2 = if jugador2 < puntos.len() {
|
||||||
|
puntos[jugador2].to_string()
|
||||||
|
} else {
|
||||||
|
"+".to_string()
|
||||||
|
};
|
||||||
|
if jugador1 > 2 && jugador2 > 2 && jugador1 == jugador2 {
|
||||||
|
println!("Deuce");
|
||||||
|
} else if jugador1 > 2 && jugador2 > 2 && jugador1 + 1 == jugador2 {
|
||||||
|
println!("Ventaja P2");
|
||||||
|
} else if jugador1 > 2 && jugador2 > 2 && jugador2 + 1 == jugador1 {
|
||||||
|
println!("Ventaja P1");
|
||||||
|
} else if jugador1 > 3 && jugador1 > jugador2 {
|
||||||
|
println!("Ha ganado el P1");
|
||||||
|
} else if jugador1 > 3 && jugador2 > jugador1 {
|
||||||
|
println!("Ha ganado el P2");
|
||||||
|
} else {
|
||||||
|
println!("{} - {}", puntos1, puntos2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
ejercicios/reto03/Cargo.toml
Normal file
9
ejercicios/reto03/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "reto04"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
rand = "0.8"
|
||||||
59
ejercicios/reto03/src/main.rs
Normal file
59
ejercicios/reto03/src/main.rs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Escribe un programa que sea capaz de generar contraseñas de forma aleatoria.
|
||||||
|
* Podrás configurar generar contraseñas con los siguientes parámetros:
|
||||||
|
* - Longitud: Entre 8 y 16.
|
||||||
|
* - Con o sin letras mayúsculas.
|
||||||
|
* - Con o sin números.
|
||||||
|
* - Con o sin símbolos.
|
||||||
|
* (Pudiendo combinar todos estos parámetros entre ellos)
|
||||||
|
*/
|
||||||
|
use rand::Rng;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// configurar:
|
||||||
|
let veces = 13;
|
||||||
|
let mayusculas = true;
|
||||||
|
let numeros = true;
|
||||||
|
let simbolos = true;
|
||||||
|
|
||||||
|
let mut caracteres = String::from_utf8((b'a'..=b'z').collect()).unwrap();
|
||||||
|
if mayusculas {
|
||||||
|
let string_mayusculas = String::from_utf8((b'A'..=b'Z').collect()).unwrap();
|
||||||
|
caracteres += string_mayusculas.to_string().as_str();
|
||||||
|
}
|
||||||
|
if numeros {
|
||||||
|
let string_numeros = String::from_utf8((b'0'..=b'9').collect()).unwrap();
|
||||||
|
caracteres += string_numeros.to_string().as_str();
|
||||||
|
}
|
||||||
|
if simbolos {
|
||||||
|
for num in 33..48 {
|
||||||
|
let u8 = num as u8;
|
||||||
|
let caracter = u8 as char;
|
||||||
|
caracteres += caracter.to_string().as_str();
|
||||||
|
}
|
||||||
|
for num in 58..65 {
|
||||||
|
let u8 = num as u8;
|
||||||
|
let caracter = u8 as char;
|
||||||
|
caracteres += caracter.to_string().as_str();
|
||||||
|
}
|
||||||
|
for num in 91..97 {
|
||||||
|
let u8 = num as u8;
|
||||||
|
let caracter = u8 as char;
|
||||||
|
caracteres += caracter.to_string().as_str();
|
||||||
|
}
|
||||||
|
for num in 123..127 {
|
||||||
|
let u8 = num as u8;
|
||||||
|
let caracter = u8 as char;
|
||||||
|
caracteres += caracter.to_string().as_str();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Caracteres: {}", caracteres);
|
||||||
|
let mut texto: String = String::new();
|
||||||
|
for _ in 0..veces {
|
||||||
|
let num = rand::thread_rng().gen_range(0..caracteres.len());
|
||||||
|
let caracter = caracteres.chars().nth(num).unwrap();
|
||||||
|
texto += caracter.to_string().as_str();
|
||||||
|
}
|
||||||
|
println!("{}", texto.to_string());
|
||||||
|
}
|
||||||
8
ejercicios/reto04/Cargo.toml
Normal file
8
ejercicios/reto04/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "reto04"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
65
ejercicios/reto04/src/main.rs
Normal file
65
ejercicios/reto04/src/main.rs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Escribe un programa que, dado un número, compruebe y muestre si es primo, fibonacci y par.
|
||||||
|
* Ejemplos:
|
||||||
|
* - Con el número 2, nos dirá: "2 es primo, fibonacci y es par"
|
||||||
|
* - Con el número 7, nos dirá: "7 es primo, no es fibonacci y es impar"
|
||||||
|
*/
|
||||||
|
|
||||||
|
fn esprimo(numero: i32) -> bool {
|
||||||
|
if numero == 0 || numero == 1 {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
for i in 2..numero {
|
||||||
|
if numero % i == 0 {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn esfibonacci(numero: i32) -> bool {
|
||||||
|
let mut vector_numeros = vec![0, 1];
|
||||||
|
let mut suma = vector_numeros[0] + vector_numeros[1];
|
||||||
|
while suma < numero {
|
||||||
|
vector_numeros.push(suma);
|
||||||
|
vector_numeros.drain(0..1);
|
||||||
|
suma = vector_numeros[0] + vector_numeros[1];
|
||||||
|
if suma > numero {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if suma == numero {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn espar(numero: i32) -> bool {
|
||||||
|
if numero % 2 == 0 {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let num = 200;
|
||||||
|
let mut texto = String::new();
|
||||||
|
texto += &num.to_string();
|
||||||
|
if esprimo(num) {
|
||||||
|
texto += " es primo";
|
||||||
|
} else {
|
||||||
|
texto += " no es primo";
|
||||||
|
}
|
||||||
|
if esfibonacci(num) {
|
||||||
|
texto += ", fibonacci";
|
||||||
|
} else {
|
||||||
|
texto += ", no es fibonacci";
|
||||||
|
}
|
||||||
|
if espar(num) {
|
||||||
|
texto += " y es par";
|
||||||
|
} else {
|
||||||
|
texto += " y es impar";
|
||||||
|
}
|
||||||
|
println!("{}", texto);
|
||||||
|
}
|
||||||
8
ejercicios/reto05/Cargo.toml
Normal file
8
ejercicios/reto05/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "reto05"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
11
ejercicios/reto05/src/main.rs
Normal file
11
ejercicios/reto05/src/main.rs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* Escribe un !Hola Mundo! en todos los lenguajes de programación que puedas.
|
||||||
|
* Seguro que hay algún lenguaje que te llama la atención y nunca has utilizado,
|
||||||
|
* o quizás quieres dar tus primeros pasos... ¡Pues este es el momento!
|
||||||
|
*
|
||||||
|
* A ver quién se atreve con uno de esos lenguajes que no solemos ver por ahí...
|
||||||
|
*/
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("Hello, world!");
|
||||||
|
}
|
||||||
9
ejercicios/reto06/Cargo.toml
Normal file
9
ejercicios/reto06/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "reto06"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
rand = "0.8"
|
||||||
52
ejercicios/reto06/src/main.rs
Normal file
52
ejercicios/reto06/src/main.rs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Crea un programa que calcule quien gana más partidas al piedra,
|
||||||
|
* papel, tijera, lagarto, spock.
|
||||||
|
* - El resultado puede ser: "Player 1", "Player 2", "Tie" (empate)
|
||||||
|
* - La función recibe un listado que contiene pares, representando cada jugada.
|
||||||
|
* - El par puede contener combinaciones de "🗿" (piedra), "📄" (papel),
|
||||||
|
* "✂️" (tijera), "🦎" (lagarto) o "🖖" (spock).
|
||||||
|
* - Ejemplo. Entrada: [("🗿","✂️"), ("✂️","🗿"), ("📄","✂️")]. Resultado: "Player 2".
|
||||||
|
* - Debes buscar información sobre cómo se juega con estas 5 posibilidades.
|
||||||
|
|
||||||
|
Reglas del juego piedra papel tijera lagarto Spock.
|
||||||
|
|
||||||
|
Tijera corta a papel.
|
||||||
|
Papel envuelve a piedra.
|
||||||
|
Piedra aplasta a lagarto.
|
||||||
|
Lagarto envenena a Spock.
|
||||||
|
Spock rompe a tijera.
|
||||||
|
Tijera decapita a lagarto.
|
||||||
|
Lagarto devora a papel.
|
||||||
|
Papel desautoriza a Spock.
|
||||||
|
Spock vaporiza a piedra.
|
||||||
|
Piedra aplasta a tijera.
|
||||||
|
*/
|
||||||
|
use rand::Rng;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let simbolos: Vec<&str> = vec!["piedra", "lagarto", "spook", "tijera", "papel"];
|
||||||
|
// random jugadas
|
||||||
|
let num1 = rand::thread_rng().gen_range(0..simbolos.len());
|
||||||
|
let num2 = rand::thread_rng().gen_range(0..simbolos.len());
|
||||||
|
let jugada: Vec<&str> = vec![simbolos[num1], simbolos[num2]];
|
||||||
|
println!("{} {}", jugada[0], jugada[1]);
|
||||||
|
if jugada[0] != jugada[1] {
|
||||||
|
let mut ordenado: Vec<&str> = Vec::new();
|
||||||
|
let mut index = simbolos.iter().position(|&r| r == jugada[0]).unwrap();
|
||||||
|
// println!("{} {}", index, jugada[0]);
|
||||||
|
for _ in 0..5 {
|
||||||
|
if index == simbolos.len() {
|
||||||
|
index = 0
|
||||||
|
}
|
||||||
|
ordenado.push(simbolos[index]);
|
||||||
|
index = index + 1;
|
||||||
|
}
|
||||||
|
if ordenado[1] == jugada[1] || ordenado[3] == jugada[1] {
|
||||||
|
println!("Player 1");
|
||||||
|
} else {
|
||||||
|
println!("Player 2");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("Empate");
|
||||||
|
}
|
||||||
|
}
|
||||||
8
ejercicios/reto07/Cargo.toml
Normal file
8
ejercicios/reto07/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "reto07"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
169
ejercicios/reto07/src/main.rs
Normal file
169
ejercicios/reto07/src/main.rs
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
/*
|
||||||
|
* Crea un programa que simule el comportamiento del sombrero selccionador del
|
||||||
|
* universo mágico de Harry Potter.
|
||||||
|
* - De ser posible realizará 5 preguntas (como mínimo) a través de la terminal.
|
||||||
|
* - Cada pregunta tendrá 4 respuestas posibles (también a selecciona una a través de terminal).
|
||||||
|
* - En función de las respuestas a las 5 preguntas deberás diseñar un algoritmo que
|
||||||
|
* coloque al alumno en una de las 4 casas de Hogwarts (Gryffindor, Slytherin , Hufflepuff y Ravenclaw)
|
||||||
|
* - Ten en cuenta los rasgos de cada casa para hacer las preguntas y crear el algoritmo seleccionador.
|
||||||
|
* Por ejemplo, en Slytherin se premia la ambición y la astucia.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use std::io;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut entrada: String = String::new();
|
||||||
|
while entrada.trim().parse::<i32>().is_err()
|
||||||
|
|| entrada.trim().parse::<i32>().unwrap() < 1
|
||||||
|
|| entrada.trim().parse::<i32>().unwrap() > 4
|
||||||
|
{
|
||||||
|
entrada.clear();
|
||||||
|
println!("Cuál es tu color preferido?");
|
||||||
|
println!("1. Azul");
|
||||||
|
println!("2. Rojo");
|
||||||
|
println!("3. Verde");
|
||||||
|
println!("4. Negro");
|
||||||
|
io::stdin().read_line(&mut entrada).unwrap();
|
||||||
|
}
|
||||||
|
let mut numero = entrada.trim().parse::<i32>().unwrap();
|
||||||
|
let mut gryffindor = 0;
|
||||||
|
let mut slytherin = 0;
|
||||||
|
let mut hufflepuff = 0;
|
||||||
|
let mut ravenclaw = 0;
|
||||||
|
match numero {
|
||||||
|
1 => gryffindor += 1,
|
||||||
|
2 => slytherin += 1,
|
||||||
|
3 => hufflepuff += 1,
|
||||||
|
4 => ravenclaw += 1,
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
entrada.clear();
|
||||||
|
while entrada.trim().parse::<i32>().is_err()
|
||||||
|
|| entrada.trim().parse::<i32>().unwrap() < 1
|
||||||
|
|| entrada.trim().parse::<i32>().unwrap() > 4
|
||||||
|
{
|
||||||
|
entrada.clear();
|
||||||
|
println!("A que velocidad vuela una paloma?");
|
||||||
|
println!("1. 130km/h");
|
||||||
|
println!("2. 340km/h");
|
||||||
|
println!("3. 500km/h");
|
||||||
|
println!("4. La europea o la asiática?");
|
||||||
|
io::stdin().read_line(&mut entrada).unwrap();
|
||||||
|
}
|
||||||
|
numero = entrada.trim().parse::<i32>().unwrap();
|
||||||
|
match numero {
|
||||||
|
2 => gryffindor += 1,
|
||||||
|
3 => slytherin += 1,
|
||||||
|
4 => hufflepuff += 1,
|
||||||
|
1 => ravenclaw += 1,
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
entrada.clear();
|
||||||
|
while entrada.trim().parse::<i32>().is_err()
|
||||||
|
|| entrada.trim().parse::<i32>().unwrap() < 1
|
||||||
|
|| entrada.trim().parse::<i32>().unwrap() > 4
|
||||||
|
{
|
||||||
|
entrada.clear();
|
||||||
|
println!("Los pelos del culo abrigan?");
|
||||||
|
println!("1. Si, digan lo que digan");
|
||||||
|
println!("2. demasiado calor");
|
||||||
|
println!("3. No, digan lo que digan");
|
||||||
|
println!("4. Que es un culo?");
|
||||||
|
io::stdin().read_line(&mut entrada).unwrap();
|
||||||
|
}
|
||||||
|
numero = entrada.trim().parse::<i32>().unwrap();
|
||||||
|
match numero {
|
||||||
|
3 => gryffindor += 1,
|
||||||
|
4 => slytherin += 1,
|
||||||
|
1 => hufflepuff += 1,
|
||||||
|
2 => ravenclaw += 1,
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
entrada.clear();
|
||||||
|
while entrada.trim().parse::<i32>().is_err()
|
||||||
|
|| entrada.trim().parse::<i32>().unwrap() < 1
|
||||||
|
|| entrada.trim().parse::<i32>().unwrap() > 4
|
||||||
|
{
|
||||||
|
entrada.clear();
|
||||||
|
println!("Desde Santurce a Bilbao");
|
||||||
|
println!("1. Voy con toa la cuadrilla");
|
||||||
|
println!("2. En coches de policia");
|
||||||
|
println!("3. Vengo deprisa y corriendo");
|
||||||
|
println!("4. Que me quiere ver el Juez?");
|
||||||
|
io::stdin().read_line(&mut entrada).unwrap();
|
||||||
|
}
|
||||||
|
numero = entrada.trim().parse::<i32>().unwrap();
|
||||||
|
match numero {
|
||||||
|
4 => gryffindor += 1,
|
||||||
|
1 => slytherin += 1,
|
||||||
|
2 => hufflepuff += 1,
|
||||||
|
3 => ravenclaw += 1,
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
entrada.clear();
|
||||||
|
while entrada.trim().parse::<i32>().is_err()
|
||||||
|
|| entrada.trim().parse::<i32>().unwrap() < 1
|
||||||
|
|| entrada.trim().parse::<i32>().unwrap() > 4
|
||||||
|
{
|
||||||
|
entrada.clear();
|
||||||
|
println!("Tipos de monederos");
|
||||||
|
println!("1. piel de pingüino");
|
||||||
|
println!("2. casco de bombero");
|
||||||
|
println!("3. escroto de jubilao");
|
||||||
|
println!("4. Que es un escroto?");
|
||||||
|
io::stdin().read_line(&mut entrada).unwrap();
|
||||||
|
}
|
||||||
|
numero = entrada.trim().parse::<i32>().unwrap();
|
||||||
|
match numero {
|
||||||
|
1 => gryffindor += 1,
|
||||||
|
2 => slytherin += 1,
|
||||||
|
3 => hufflepuff += 1,
|
||||||
|
4 => ravenclaw += 1,
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
let mut vec = vec![gryffindor, slytherin, hufflepuff, ravenclaw];
|
||||||
|
println!(
|
||||||
|
"Griffindor: {}, Slytherin: {}, Hufflepuff: {}, Ravenclaw: {}",
|
||||||
|
gryffindor, slytherin, hufflepuff, ravenclaw
|
||||||
|
);
|
||||||
|
vec.sort();
|
||||||
|
// Aquí decidimos el ganador
|
||||||
|
|
||||||
|
if vec[vec.len() - 1] == vec[vec.len() - 2] {
|
||||||
|
let mut ganador1 = String::from("");
|
||||||
|
let mut ganador2 = String::from("");
|
||||||
|
if gryffindor == vec[vec.len() - 1] {
|
||||||
|
ganador1 = String::from("Gryffindor");
|
||||||
|
}
|
||||||
|
if slytherin == vec[vec.len() - 1] {
|
||||||
|
if ganador1 == String::from("") {
|
||||||
|
ganador1 = String::from("Slytherin");
|
||||||
|
} else {
|
||||||
|
ganador2 = String::from("Slytherin");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if hufflepuff == vec[vec.len() - 1] {
|
||||||
|
if ganador1 == String::from("") {
|
||||||
|
ganador1 = String::from("Hufflepuff");
|
||||||
|
} else {
|
||||||
|
ganador2 = String::from("Hufflepuff");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ravenclaw == vec[vec.len() - 1] {
|
||||||
|
ganador2 = String::from("Ravenclaw");
|
||||||
|
}
|
||||||
|
println!("Los ganadores son: {} y {}", ganador1, ganador2);
|
||||||
|
} else {
|
||||||
|
let mut ganador = String::from("");
|
||||||
|
if gryffindor == vec[vec.len() - 1] {
|
||||||
|
ganador = String::from("Gryffindor");
|
||||||
|
} else if slytherin == vec[vec.len() - 1] {
|
||||||
|
ganador = String::from("Slytherin");
|
||||||
|
} else if hufflepuff == vec[vec.len() - 1] {
|
||||||
|
ganador = String::from("Hufflepuff");
|
||||||
|
} else if ravenclaw == vec[vec.len() - 1] {
|
||||||
|
ganador = String::from("Ravenclaw");
|
||||||
|
}
|
||||||
|
println!("El ganador es: {}", ganador);
|
||||||
|
}
|
||||||
|
}
|
||||||
8
ejercicios/reto08/Cargo.toml
Normal file
8
ejercicios/reto08/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "reto08"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
34
ejercicios/reto08/src/main.rs
Normal file
34
ejercicios/reto08/src/main.rs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Crea un generador de números pseudoaleatorios entre 0 y 100.
|
||||||
|
* - No puedes usar ninguna función "random" (o semejante) del lenguaje de programación seleccionado.
|
||||||
|
*
|
||||||
|
* Es más complicado de lo que parece...
|
||||||
|
*/
|
||||||
|
use std::time::SystemTime;
|
||||||
|
use std::time::UNIX_EPOCH;
|
||||||
|
|
||||||
|
fn seudorandom() -> u32 {
|
||||||
|
let mut now = SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.unwrap()
|
||||||
|
.as_nanos()
|
||||||
|
.to_string()
|
||||||
|
.chars()
|
||||||
|
.collect::<String>()
|
||||||
|
.split("")
|
||||||
|
.collect::<Vec<&str>>()[10..13]
|
||||||
|
.join("")
|
||||||
|
.parse::<u32>()
|
||||||
|
.unwrap() as u32;
|
||||||
|
|
||||||
|
while now > 100 {
|
||||||
|
println!("{}", now);
|
||||||
|
now = now - 101;
|
||||||
|
}
|
||||||
|
now
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let numero = seudorandom();
|
||||||
|
println!("El número es: {}", numero);
|
||||||
|
}
|
||||||
8
ejercicios/reto09/Cargo.toml
Normal file
8
ejercicios/reto09/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "reto09"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
78
ejercicios/reto09/src/main.rs
Normal file
78
ejercicios/reto09/src/main.rs
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Crea 3 funciones, cada una encargada de detectar si una cadena de
|
||||||
|
* texto es un heterograma, un isograma o un pangrama.
|
||||||
|
* - Debes buscar la definición de cada uno de estos términos.
|
||||||
|
* Heterograma: un conjunto de caracteres que no se repiten.
|
||||||
|
* Isograma: palabra sin letras repetidas (como ambidiestramente ) o, más ampliamente, una palabra en la que las letras aparecen el mismo número de veces.
|
||||||
|
* Pangrama: texto que contiene todas las letras del abecedario. Tengo un libro de papiroflexia sobre las hazañas y aventuras de Don Quijote de la Mancha en Kuwait.
|
||||||
|
*/
|
||||||
|
|
||||||
|
fn esheterograma(cadena: &str) -> bool {
|
||||||
|
let vectorcadena: Vec<char> = cadena.chars().collect();
|
||||||
|
let mut vectorvacio: Vec<char> = vec![];
|
||||||
|
for letra in vectorcadena.iter() {
|
||||||
|
if vectorvacio.contains(letra) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
vectorvacio.push(*letra);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn esisograma(cadena: &str) -> bool {
|
||||||
|
let vectorcadena: Vec<char> = cadena.chars().collect();
|
||||||
|
let mut vectorcadenasinrepetir: Vec<char> = vec![];
|
||||||
|
let mut vectorvacio: Vec<i32> = vec![];
|
||||||
|
for letra in vectorcadena.iter() {
|
||||||
|
if !vectorcadenasinrepetir.contains(letra) {
|
||||||
|
// si no está se le añade un 1 al vector de numeros
|
||||||
|
vectorcadenasinrepetir.push(*letra);
|
||||||
|
vectorvacio.push(1);
|
||||||
|
} else {
|
||||||
|
// si está hay que buscarla y sumarle un 1 al vector de numeros
|
||||||
|
let index = vectorcadenasinrepetir
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.find(|&r| r.1.to_string() == letra.to_string())
|
||||||
|
.unwrap()
|
||||||
|
.0;
|
||||||
|
vectorvacio[index] += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i in vectorvacio.iter() {
|
||||||
|
if i != &vectorvacio[0] {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn espangrama(cadena: &str) -> bool {
|
||||||
|
let vectorcadena: Vec<char> = cadena.chars().collect();
|
||||||
|
let mut vectorabecedario: Vec<char> = [
|
||||||
|
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'ñ', 'o', 'p', 'q',
|
||||||
|
'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||||
|
]
|
||||||
|
.to_vec();
|
||||||
|
for letra in vectorcadena.iter() {
|
||||||
|
if !vectorabecedario.contains(letra) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
let index = vectorabecedario
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.find(|&r| r.1.to_string() == letra.to_string())
|
||||||
|
.unwrap()
|
||||||
|
.0;
|
||||||
|
vectorabecedario.remove(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("{}", esheterograma("mis coj"));
|
||||||
|
println!("{}", esisograma("aabbccdgged"));
|
||||||
|
println!("{}", espangrama("abcdefghijklmnñopqrstuwxyza"));
|
||||||
|
}
|
||||||
10
ejercicios/reto10/Cargo.toml
Normal file
10
ejercicios/reto10/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "reto10"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
reqwest = "0.11.12"
|
||||||
|
tokio = {version = "1", features = ["full"]}
|
||||||
23
ejercicios/reto10/src/main.rs
Normal file
23
ejercicios/reto10/src/main.rs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Llamar a una API es una de las tareas más comunes en programación.
|
||||||
|
*
|
||||||
|
* Implementa una llamada HTTP a una API (la que tú quieras) y muestra su
|
||||||
|
* resultado a través de la terminal. Por ejemplo: Pokémon, Marvel...
|
||||||
|
*
|
||||||
|
* Aquí tienes un listado de posibles APIs:
|
||||||
|
* https://github.com/public-apis/public-apis
|
||||||
|
*/
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let html: String = reqwest::get("https://bible-api.com/john%203:16") // Se pasa el url o endpoint con el cual se interacturara
|
||||||
|
.await? // Hace que reqwest espere por la respuesta del servidor
|
||||||
|
.text() //Convierte el resultado en un String
|
||||||
|
.await?;
|
||||||
|
// println!("{:?}", html);
|
||||||
|
let texto = html.as_str();
|
||||||
|
let vector: Vec<&str> = texto.split(":").collect();
|
||||||
|
println!("{}", vector[8]);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
8
ejercicios/reto11/Cargo.toml
Normal file
8
ejercicios/reto11/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "reto11"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user