From a40913fcd403a6e4c6e2ebcfb6abb06ad7ff3b8f Mon Sep 17 00:00:00 2001 From: mmo Date: Thu, 25 Aug 2022 11:41:05 +0200 Subject: [PATCH] add solutions --- exercises/if/if1.rs | 11 +++++++++++ exercises/if/if2.rs | 9 ++++++--- exercises/primitive_types/primitive_types1.rs | 3 +-- exercises/primitive_types/primitive_types2.rs | 3 +-- exercises/quiz1.rs | 10 ++++++++-- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/exercises/if/if1.rs b/exercises/if/if1.rs index bcdff41e..70b49d57 100644 --- a/exercises/if/if1.rs +++ b/exercises/if/if1.rs @@ -7,6 +7,17 @@ pub fn bigger(a: i32, b: i32) -> i32 { // Do not use: // - another function call // - additional variables + + if a > b { + a + } + else if b > a { + b + } + else { + a + } + } // Don't mind this for now :) diff --git a/exercises/if/if2.rs b/exercises/if/if2.rs index effddbb6..a9b80dfe 100644 --- a/exercises/if/if2.rs +++ b/exercises/if/if2.rs @@ -4,13 +4,16 @@ // Step 2: Get the bar_for_fuzz and default_to_baz tests passing! // Execute `rustlings hint if2` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE pub fn foo_if_fizz(fizzish: &str) -> &str { if fizzish == "fizz" { "foo" - } else { - 1 + } + else if fizzish == "fuzz" { + "bar" + } + else { + "baz" } } diff --git a/exercises/primitive_types/primitive_types1.rs b/exercises/primitive_types/primitive_types1.rs index 09121392..2466419e 100644 --- a/exercises/primitive_types/primitive_types1.rs +++ b/exercises/primitive_types/primitive_types1.rs @@ -2,7 +2,6 @@ // Fill in the rest of the line that has code missing! // No hints, there's no tricks, just get used to typing these :) -// I AM NOT DONE fn main() { // Booleans (`bool`) @@ -12,7 +11,7 @@ fn main() { println!("Good morning!"); } - let // Finish the rest of this line like the example! Or make it be false! + let is_evening = false;// Finish the rest of this line like the example! Or make it be false! if is_evening { println!("Good evening!"); } diff --git a/exercises/primitive_types/primitive_types2.rs b/exercises/primitive_types/primitive_types2.rs index 8730baab..f886687e 100644 --- a/exercises/primitive_types/primitive_types2.rs +++ b/exercises/primitive_types/primitive_types2.rs @@ -2,7 +2,6 @@ // Fill in the rest of the line that has code missing! // No hints, there's no tricks, just get used to typing these :) -// I AM NOT DONE fn main() { // Characters (`char`) @@ -18,7 +17,7 @@ fn main() { println!("Neither alphabetic nor numeric!"); } - let // Finish this line like the example! What's your favorite character? + let your_character:char = 'ß'; // Finish this line like the example! What's your favorite character? // Try a letter, try a number, try a special character, try a character // from a different language than your own, try an emoji! if your_character.is_alphabetic() { diff --git a/exercises/quiz1.rs b/exercises/quiz1.rs index 8d05b110..978b1cc7 100644 --- a/exercises/quiz1.rs +++ b/exercises/quiz1.rs @@ -8,10 +8,16 @@ // 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_price_of_apples { +fn calculate_price_of_apples(num:u32) -> u32 { + if num > 40 { + num + } + else { + num * 2 + } +} // Don't modify this function! #[test]