From a3143f4ff766950429897b56f13ba9c90ddd7b52 Mon Sep 17 00:00:00 2001 From: Chris Girvin Date: Sat, 14 May 2022 17:13:39 -0400 Subject: [PATCH 1/3] functions done --- exercises/functions/functions1.rs | 3 ++- exercises/functions/functions2.rs | 3 +-- exercises/functions/functions3.rs | 3 +-- exercises/functions/functions4.rs | 3 +-- exercises/functions/functions5.rs | 3 +-- 5 files changed, 6 insertions(+), 9 deletions(-) diff --git a/exercises/functions/functions1.rs b/exercises/functions/functions1.rs index 31125278..266b6ece 100644 --- a/exercises/functions/functions1.rs +++ b/exercises/functions/functions1.rs @@ -1,8 +1,9 @@ // functions1.rs // Make me compile! Execute `rustlings hint functions1` for hints :) -// I AM NOT DONE fn main() { call_me(); + + fn call_me() { println!("{}", String::from("Hello")) }; } diff --git a/exercises/functions/functions2.rs b/exercises/functions/functions2.rs index 5721a172..356268ba 100644 --- a/exercises/functions/functions2.rs +++ b/exercises/functions/functions2.rs @@ -1,13 +1,12 @@ // functions2.rs // Make me compile! Execute `rustlings hint functions2` for hints :) -// I AM NOT DONE fn main() { call_me(3); } -fn call_me(num:) { +fn call_me(num: u32) { for i in 0..num { println!("Ring! Call number {}", i + 1); } diff --git a/exercises/functions/functions3.rs b/exercises/functions/functions3.rs index ed5f839f..c01dbec6 100644 --- a/exercises/functions/functions3.rs +++ b/exercises/functions/functions3.rs @@ -1,10 +1,9 @@ // functions3.rs // Make me compile! Execute `rustlings hint functions3` for hints :) -// I AM NOT DONE fn main() { - call_me(); + call_me(5); } fn call_me(num: u32) { diff --git a/exercises/functions/functions4.rs b/exercises/functions/functions4.rs index 58637e4c..0c3c6c30 100644 --- a/exercises/functions/functions4.rs +++ b/exercises/functions/functions4.rs @@ -4,14 +4,13 @@ // This store is having a sale where if the price is an even number, you get // 10 Rustbucks off, but if it's an odd number, it's 3 Rustbucks off. -// I AM NOT DONE fn main() { let original_price = 51; println!("Your sale price is {}", sale_price(original_price)); } -fn sale_price(price: i32) -> { +fn sale_price(price: i32) -> i32 { if is_even(price) { price - 10 } else { diff --git a/exercises/functions/functions5.rs b/exercises/functions/functions5.rs index d22aa6c8..ee79e792 100644 --- a/exercises/functions/functions5.rs +++ b/exercises/functions/functions5.rs @@ -1,7 +1,6 @@ // functions5.rs // Make me compile! Execute `rustlings hint functions5` for hints :) -// I AM NOT DONE fn main() { let answer = square(3); @@ -9,5 +8,5 @@ fn main() { } fn square(num: i32) -> i32 { - num * num; + num * num } From f1722f119d73025a61cbe2a26b1f9b8314f851f6 Mon Sep 17 00:00:00 2001 From: Chris Girvin Date: Sat, 14 May 2022 17:31:47 -0400 Subject: [PATCH 2/3] quiz1 done --- exercises/if/if1.rs | 8 +++++++- exercises/if/if2.rs | 5 +++-- exercises/quiz1.rs | 10 +++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/exercises/if/if1.rs b/exercises/if/if1.rs index 90867545..d3f4f05f 100644 --- a/exercises/if/if1.rs +++ b/exercises/if/if1.rs @@ -1,6 +1,5 @@ // if1.rs -// I AM NOT DONE pub fn bigger(a: i32, b: i32) -> i32 { // Complete this function to return the bigger number! @@ -8,6 +7,13 @@ pub fn bigger(a: i32, b: i32) -> i32 { // - another function call // - additional variables // Execute `rustlings hint if1` for hints + let gt = if a < b { + b + } else { + a + }; + + return gt; } // Don't mind this for now :) diff --git a/exercises/if/if2.rs b/exercises/if/if2.rs index 80effbdf..4d1ab2d4 100644 --- a/exercises/if/if2.rs +++ b/exercises/if/if2.rs @@ -4,13 +4,14 @@ // Step 2: Get the bar_for_fuzz and default_to_baz tests passing! // Execute the command `rustlings hint if2` if you want a hint :) -// I AM NOT DONE pub fn fizz_if_foo(fizzish: &str) -> &str { if fizzish == "fizz" { "foo" + } else if fizzish == "fuzz" { + "bar" } else { - 1 + "baz" } } diff --git a/exercises/quiz1.rs b/exercises/quiz1.rs index 7bd3f589..773089bc 100644 --- a/exercises/quiz1.rs +++ b/exercises/quiz1.rs @@ -8,10 +8,18 @@ // more than 40 at once, each apple only costs 1! Write a function that calculates // the price of an order of apples given the quantity bought. No hints this time! -// I AM NOT DONE // Put your function here! // fn calculate_apple_price { +fn calculate_apple_price(count: u32) -> u32 { + let tot_price = if count > 40 { + count * 1 + } else { + count * 2 + }; + + return tot_price; +} // Don't modify this function! #[test] From ef4ee0407f4ecfecc38d968cd7c4dc7ac4e77a59 Mon Sep 17 00:00:00 2001 From: Chris Girvin Date: Sat, 14 May 2022 20:42:08 -0400 Subject: [PATCH 3/3] move_semantics2 --- exercises/move_semantics/move_semantics1.rs | 3 +-- exercises/move_semantics/move_semantics2.rs | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/exercises/move_semantics/move_semantics1.rs b/exercises/move_semantics/move_semantics1.rs index e2f5876d..78e4f8aa 100644 --- a/exercises/move_semantics/move_semantics1.rs +++ b/exercises/move_semantics/move_semantics1.rs @@ -1,12 +1,11 @@ // move_semantics1.rs // Make me compile! Execute `rustlings hint move_semantics1` for hints :) -// I AM NOT DONE fn main() { let vec0 = Vec::new(); - let vec1 = fill_vec(vec0); + let mut vec1 = fill_vec(vec0); println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1); diff --git a/exercises/move_semantics/move_semantics2.rs b/exercises/move_semantics/move_semantics2.rs index 888dc529..3704c198 100644 --- a/exercises/move_semantics/move_semantics2.rs +++ b/exercises/move_semantics/move_semantics2.rs @@ -7,6 +7,9 @@ fn main() { let vec0 = Vec::new(); + // solution 1 + // let mut vec0_copy = &vec0; + // let mut vec1 = fill_vec(vec0_copy.to_vec()); let mut vec1 = fill_vec(vec0); // Do not change the following line!