From 56b04dbc4d747f22db8db6be19e323cb2c2813f5 Mon Sep 17 00:00:00 2001 From: Jorge Esparza Date: Fri, 20 Feb 2026 23:56:39 -0600 Subject: [PATCH] 1 to 3 excercises --- exercises/00_intro/intro2.rs | 2 +- exercises/01_variables/variables1.rs | 2 +- exercises/01_variables/variables2.rs | 4 ++-- exercises/01_variables/variables3.rs | 2 +- exercises/01_variables/variables4.rs | 2 +- exercises/01_variables/variables5.rs | 4 ++-- exercises/01_variables/variables6.rs | 2 +- exercises/02_functions/functions1.rs | 4 +++- exercises/02_functions/functions2.rs | 2 +- exercises/02_functions/functions3.rs | 2 +- exercises/02_functions/functions4.rs | 2 +- exercises/02_functions/functions5.rs | 2 +- exercises/03_if/if1.rs | 5 +++++ exercises/03_if/if2.rs | 4 +++- exercises/03_if/if3.rs | 6 +++--- release-hook.sh | 2 +- 16 files changed, 28 insertions(+), 19 deletions(-) diff --git a/exercises/00_intro/intro2.rs b/exercises/00_intro/intro2.rs index c6cb6451..03e376ed 100644 --- a/exercises/00_intro/intro2.rs +++ b/exercises/00_intro/intro2.rs @@ -1,4 +1,4 @@ fn main() { // TODO: Fix the code to print "Hello world!". - printline!("Hello world!"); + println!("Hello world!"); } diff --git a/exercises/01_variables/variables1.rs b/exercises/01_variables/variables1.rs index f83b44d4..ec1bcacb 100644 --- a/exercises/01_variables/variables1.rs +++ b/exercises/01_variables/variables1.rs @@ -1,6 +1,6 @@ fn main() { // TODO: Add the missing keyword. - x = 5; + let x = 5; println!("x has the value {x}"); } diff --git a/exercises/01_variables/variables2.rs b/exercises/01_variables/variables2.rs index e2a36035..1b90dc78 100644 --- a/exercises/01_variables/variables2.rs +++ b/exercises/01_variables/variables2.rs @@ -1,8 +1,8 @@ fn main() { // TODO: Change the line below to fix the compiler error. - let x; + let x = 42; - if x == 10 { + if 10 == x { println!("x is ten!"); } else { println!("x is not ten!"); diff --git a/exercises/01_variables/variables3.rs b/exercises/01_variables/variables3.rs index 06f35bb1..56e6ef08 100644 --- a/exercises/01_variables/variables3.rs +++ b/exercises/01_variables/variables3.rs @@ -1,6 +1,6 @@ fn main() { // TODO: Change the line below to fix the compiler error. - let x: i32; + let x: i32 = 42; println!("Number {x}"); } diff --git a/exercises/01_variables/variables4.rs b/exercises/01_variables/variables4.rs index 6c138b18..90d4ef05 100644 --- a/exercises/01_variables/variables4.rs +++ b/exercises/01_variables/variables4.rs @@ -1,6 +1,6 @@ // TODO: Fix the compiler error. fn main() { - let x = 3; + let mut x = 3; println!("Number {x}"); x = 5; // Don't change this line diff --git a/exercises/01_variables/variables5.rs b/exercises/01_variables/variables5.rs index cf5620da..10cf9022 100644 --- a/exercises/01_variables/variables5.rs +++ b/exercises/01_variables/variables5.rs @@ -3,6 +3,6 @@ fn main() { println!("Spell a number: {number}"); // TODO: Fix the compiler error by changing the line below without renaming the variable. - number = 3; - println!("Number plus two is: {}", number + 2); + let number2 = 3; + println!("Number plus two is: {}", number2 + 2); } diff --git a/exercises/01_variables/variables6.rs b/exercises/01_variables/variables6.rs index 4a040fdd..deb33ed9 100644 --- a/exercises/01_variables/variables6.rs +++ b/exercises/01_variables/variables6.rs @@ -1,5 +1,5 @@ // TODO: Change the line below to fix the compiler error. -const NUMBER = 3; +const NUMBER: i32 = 3; fn main() { println!("Number: {NUMBER}"); diff --git a/exercises/02_functions/functions1.rs b/exercises/02_functions/functions1.rs index a812c21b..677b5fed 100644 --- a/exercises/02_functions/functions1.rs +++ b/exercises/02_functions/functions1.rs @@ -1,5 +1,7 @@ // TODO: Add some function with the name `call_me` without arguments or a return value. - +fn call_me() { + println!("You called me!"); +} fn main() { call_me(); // Don't change this line } diff --git a/exercises/02_functions/functions2.rs b/exercises/02_functions/functions2.rs index 2c773c6b..9d51064b 100644 --- a/exercises/02_functions/functions2.rs +++ b/exercises/02_functions/functions2.rs @@ -1,5 +1,5 @@ // TODO: Add the missing type of the argument `num` after the colon `:`. -fn call_me(num:) { +fn call_me(num:u32) { for i in 0..num { println!("Ring! Call number {}", i + 1); } diff --git a/exercises/02_functions/functions3.rs b/exercises/02_functions/functions3.rs index 8d654772..a226e666 100644 --- a/exercises/02_functions/functions3.rs +++ b/exercises/02_functions/functions3.rs @@ -6,5 +6,5 @@ fn call_me(num: u8) { fn main() { // TODO: Fix the function call. - call_me(); + call_me(1); } diff --git a/exercises/02_functions/functions4.rs b/exercises/02_functions/functions4.rs index b22bffda..60ab17d4 100644 --- a/exercises/02_functions/functions4.rs +++ b/exercises/02_functions/functions4.rs @@ -8,7 +8,7 @@ fn is_even(num: i64) -> bool { } // TODO: Fix the function signature. -fn sale_price(price: i64) -> { +fn sale_price(price: i64) -> i64{ if is_even(price) { price - 10 } else { diff --git a/exercises/02_functions/functions5.rs b/exercises/02_functions/functions5.rs index 34a2ac7d..a0631004 100644 --- a/exercises/02_functions/functions5.rs +++ b/exercises/02_functions/functions5.rs @@ -1,6 +1,6 @@ // TODO: Fix the function body without changing the signature. fn square(num: i32) -> i32 { - num * num; + num * num } fn main() { diff --git a/exercises/03_if/if1.rs b/exercises/03_if/if1.rs index e5a3c5a5..b1a304d4 100644 --- a/exercises/03_if/if1.rs +++ b/exercises/03_if/if1.rs @@ -4,6 +4,11 @@ fn bigger(a: i32, b: i32) -> i32 { // Do not use: // - another function call // - additional variables + if a > b { + a + } else { + b + } } fn main() { diff --git a/exercises/03_if/if2.rs b/exercises/03_if/if2.rs index ca8493cc..81044875 100644 --- a/exercises/03_if/if2.rs +++ b/exercises/03_if/if2.rs @@ -2,8 +2,10 @@ fn picky_eater(food: &str) -> &str { if food == "strawberry" { "Yummy!" + } else if food == "potato" { + "I guess I can eat that." } else { - 1 + "No thanks!" } } diff --git a/exercises/03_if/if3.rs b/exercises/03_if/if3.rs index 89164eb2..ce629330 100644 --- a/exercises/03_if/if3.rs +++ b/exercises/03_if/if3.rs @@ -1,13 +1,13 @@ fn animal_habitat(animal: &str) -> &str { // TODO: Fix the compiler error in the statement below. let identifier = if animal == "crab" { - 1 + 1 } else if animal == "gopher" { - 2.0 + 2 } else if animal == "snake" { 3 } else { - "Unknown" + 4 }; // Don't change the expression below! diff --git a/release-hook.sh b/release-hook.sh index 49349337..b29e58f4 100755 --- a/release-hook.sh +++ b/release-hook.sh @@ -4,7 +4,7 @@ set -e typos -cargo upgrades +# cargo upgrades # Similar to CI cargo clippy -- --deny warnings