corrección números de los retos & reto03
This commit is contained in:
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "reto03"
|
name = "reto04"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
rand = "0.8"
|
||||||
|
|||||||
@@ -1,57 +1,25 @@
|
|||||||
/*
|
/*
|
||||||
* Escribe un programa que muestre cómo transcurre un juego de tenis y quién lo ha ganado.
|
* Escribe un programa que sea capaz de generar contraseñas de forma aleatoria.
|
||||||
* El programa recibirá una secuencia formada por "P1" (Player 1) o "P2" (Player 2), según quien
|
* Podrás configurar generar contraseñas con los siguientes parámetros:
|
||||||
* gane cada punto del juego.
|
* - Longitud: Entre 8 y 16.
|
||||||
*
|
* - Con o sin letras mayúsculas.
|
||||||
* - Las puntuaciones de un juego son "Love" (cero), 15, 30, 40, "Deuce" (empate), ventaja.
|
* - Con o sin números.
|
||||||
* - Ante la secuencia [P1, P1, P2, P2, P1, P2, P1, P1], el programa mostraría lo siguiente:
|
* - Con o sin símbolos.
|
||||||
* 15 - Love
|
* (Pudiendo combinar todos estos parámetros entre ellos)
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
|
use rand::Rng; // 0.8.5
|
||||||
|
//
|
||||||
fn main() {
|
fn main() {
|
||||||
let secuencia = vec!["P1", "P1", "P2", "P2", "P1", "P2", "P1", "P1"];
|
let mut ch: char = 'A';
|
||||||
let puntos = vec!["Love", "15", "30", "40"];
|
|
||||||
let mut jugador1 = 0;
|
println!("ASCII value: {}", ch as u32);
|
||||||
let mut jugador2 = 0;
|
|
||||||
let mut puntos1;
|
ch = '&';
|
||||||
let mut puntos2;
|
println!("ASCII value: {}", ch as u32);
|
||||||
for ele in secuencia {
|
|
||||||
if ele == "P1" {
|
ch = 'X';
|
||||||
jugador1 += 1;
|
println!("ASCII value: {}", ch as u32);
|
||||||
} else if ele == "P2" {
|
|
||||||
jugador2 += 1;
|
let num: u8 = rand::thread_rng().gen_range(0..255);
|
||||||
}
|
println!("{}", num as char);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user