From c91e063beca4f7826e2e54b1ee61c2a3d20799dc Mon Sep 17 00:00:00 2001 From: ____marcell <0000marcell@gmail.com> Date: Tue, 25 Aug 2020 01:01:52 +0000 Subject: [PATCH] wip --- Cargo.lock | 2 +- exercises/functions/functions1.rs | 4 +++- exercises/functions/functions2.rs | 4 +--- exercises/functions/functions3.rs | 4 +--- exercises/functions/functions4.rs | 6 ++---- exercises/functions/functions5.rs | 6 ++---- exercises/if/if1.rs | 12 +++++------- exercises/if/if2.rs | 8 ++++---- exercises/primitive_types/primitive_types1.rs | 4 +--- exercises/primitive_types/primitive_types2.rs | 6 +----- exercises/primitive_types/primitive_types3.rs | 4 +--- exercises/primitive_types/primitive_types4.rs | 4 +--- exercises/primitive_types/primitive_types5.rs | 4 +--- exercises/primitive_types/primitive_types6.rs | 4 +--- exercises/quiz1.rs | 10 +++++++--- exercises/structs/structs1.rs | 12 +++++++----- exercises/variables/variables1.rs | 4 +--- exercises/variables/variables2.rs | 4 +--- exercises/variables/variables3.rs | 4 +--- exercises/variables/variables4.rs | 4 +--- exercises/variables/variables5.rs | 6 ++---- exercises/variables/variables6.rs | 4 +--- 22 files changed, 46 insertions(+), 74 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 52c8ed45..732a4b59 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -592,7 +592,7 @@ dependencies = [ [[package]] name = "rustlings" -version = "3.0.0" +version = "4.0.0" dependencies = [ "assert_cmd 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/exercises/functions/functions1.rs b/exercises/functions/functions1.rs index 31125278..76ae297a 100644 --- a/exercises/functions/functions1.rs +++ b/exercises/functions/functions1.rs @@ -1,7 +1,9 @@ // functions1.rs // Make me compile! Execute `rustlings hint functions1` for hints :) -// I AM NOT DONE +fn call_me() { + println!("hello world!"); +} fn main() { call_me(); diff --git a/exercises/functions/functions2.rs b/exercises/functions/functions2.rs index 108ba38b..f46f8a80 100644 --- a/exercises/functions/functions2.rs +++ b/exercises/functions/functions2.rs @@ -1,13 +1,11 @@ // 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 e3c1bf73..4ae2f9af 100644 --- a/exercises/functions/functions3.rs +++ b/exercises/functions/functions3.rs @@ -1,10 +1,8 @@ // functions3.rs // Make me compile! Execute `rustlings hint functions3` for hints :) -// I AM NOT DONE - fn main() { - call_me(); + call_me(3); } fn call_me(num: i32) { diff --git a/exercises/functions/functions4.rs b/exercises/functions/functions4.rs index 58637e4c..88196de5 100644 --- a/exercises/functions/functions4.rs +++ b/exercises/functions/functions4.rs @@ -4,14 +4,12 @@ // 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; + let original_price:i32 = 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..53c071a3 100644 --- a/exercises/functions/functions5.rs +++ b/exercises/functions/functions5.rs @@ -1,13 +1,11 @@ // functions5.rs // Make me compile! Execute `rustlings hint functions5` for hints :) -// I AM NOT DONE - fn main() { - let answer = square(3); + let answer:i32 = square(3); println!("The answer is {}", answer); } fn square(num: i32) -> i32 { - num * num; + return num * num; } diff --git a/exercises/if/if1.rs b/exercises/if/if1.rs index 90867545..21a3791b 100644 --- a/exercises/if/if1.rs +++ b/exercises/if/if1.rs @@ -1,13 +1,11 @@ // if1.rs -// I AM NOT DONE - pub fn bigger(a: i32, b: i32) -> i32 { - // Complete this function to return the bigger number! - // Do not use: - // - another function call - // - additional variables - // Execute `rustlings hint if1` for hints + if a > b { + return a; + } else { + return b; + } } // Don't mind this for now :) diff --git a/exercises/if/if2.rs b/exercises/if/if2.rs index 80effbdf..8f82c811 100644 --- a/exercises/if/if2.rs +++ b/exercises/if/if2.rs @@ -4,13 +4,13 @@ // 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" + return "foo"; + } else if fizzish == "fuzz" { + return "bar"; } else { - 1 + return "baz"; } } diff --git a/exercises/primitive_types/primitive_types1.rs b/exercises/primitive_types/primitive_types1.rs index 09121392..f0ab8acb 100644 --- a/exercises/primitive_types/primitive_types1.rs +++ b/exercises/primitive_types/primitive_types1.rs @@ -2,8 +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 +10,7 @@ fn main() { println!("Good morning!"); } - let // Finish the rest of this line like the example! Or make it be false! + let is_evening = true; if is_evening { println!("Good evening!"); } diff --git a/exercises/primitive_types/primitive_types2.rs b/exercises/primitive_types/primitive_types2.rs index 6576a4d5..75e1da81 100644 --- a/exercises/primitive_types/primitive_types2.rs +++ b/exercises/primitive_types/primitive_types2.rs @@ -2,8 +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`) @@ -16,9 +14,7 @@ fn main() { println!("Neither alphabetic nor numeric!"); } - let // 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! + let your_character = 'x'; if your_character.is_alphabetic() { println!("Alphabetical!"); } else if your_character.is_numeric() { diff --git a/exercises/primitive_types/primitive_types3.rs b/exercises/primitive_types/primitive_types3.rs index dfd6351c..366ae208 100644 --- a/exercises/primitive_types/primitive_types3.rs +++ b/exercises/primitive_types/primitive_types3.rs @@ -2,10 +2,8 @@ // Create an array with at least 100 elements in it where the ??? is. // Execute `rustlings hint primitive_types3` for hints! -// I AM NOT DONE - fn main() { - let a = ??? + let a = (1..400); if a.len() >= 100 { println!("Wow, that's a big array!"); diff --git a/exercises/primitive_types/primitive_types4.rs b/exercises/primitive_types/primitive_types4.rs index 10b553e9..d773c137 100644 --- a/exercises/primitive_types/primitive_types4.rs +++ b/exercises/primitive_types/primitive_types4.rs @@ -2,13 +2,11 @@ // Get a slice out of Array a where the ??? is so that the test passes. // Execute `rustlings hint primitive_types4` for hints!! -// I AM NOT DONE - #[test] fn slice_out_of_array() { let a = [1, 2, 3, 4, 5]; - let nice_slice = ??? + let nice_slice = &a[1..4]; assert_eq!([2, 3, 4], nice_slice) } diff --git a/exercises/primitive_types/primitive_types5.rs b/exercises/primitive_types/primitive_types5.rs index 680d8d23..85f42cfc 100644 --- a/exercises/primitive_types/primitive_types5.rs +++ b/exercises/primitive_types/primitive_types5.rs @@ -2,11 +2,9 @@ // Destructure the `cat` tuple so that the println will work. // Execute `rustlings hint primitive_types5` for hints! -// I AM NOT DONE - fn main() { let cat = ("Furry McFurson", 3.5); - let /* your pattern here */ = cat; + let (name, age) = cat; println!("{} is {} years old.", name, age); } diff --git a/exercises/primitive_types/primitive_types6.rs b/exercises/primitive_types/primitive_types6.rs index 2bc817e9..ef4f1611 100644 --- a/exercises/primitive_types/primitive_types6.rs +++ b/exercises/primitive_types/primitive_types6.rs @@ -3,9 +3,7 @@ // You can put this right into the `println!` where the ??? is. // Execute `rustlings hint primitive_types6` for hints! -// I AM NOT DONE - fn main() { let numbers = (1, 2, 3); - println!("The second number is {}", ???); + println!("The second number is {}", numbers.1); } diff --git a/exercises/quiz1.rs b/exercises/quiz1.rs index 5c5c355d..c93da1f2 100644 --- a/exercises/quiz1.rs +++ b/exercises/quiz1.rs @@ -7,10 +7,14 @@ // more than 40 at once, each apple only costs 1! Write a function that calculates // the price of an order of apples given the order amount. No hints this time! -// I AM NOT DONE - // Put your function here! -// fn ..... { +fn calculate_apple_price(number:u32) -> u32 { + let mut apple_price:u32 = 2; + if number > 40 { + apple_price = 1; + } + return apple_price * number; +} // Don't modify this function! #[test] diff --git a/exercises/structs/structs1.rs b/exercises/structs/structs1.rs index 6d0b2f49..92091add 100644 --- a/exercises/structs/structs1.rs +++ b/exercises/structs/structs1.rs @@ -1,13 +1,12 @@ // structs1.rs // Address all the TODOs to make the tests pass! -// I AM NOT DONE - struct ColorClassicStruct { - // TODO: Something goes here + name: String, + hex: String } -struct ColorTupleStruct(/* TODO: Something goes here */); +struct ColorTupleStruct("green", "#00FF00"); #[derive(Debug)] struct UnitStruct; @@ -19,7 +18,10 @@ mod tests { #[test] fn classic_c_structs() { // TODO: Instantiate a classic c struct! - // let green = + let green = { + name: "green", + hex: "#00FF00" + }; assert_eq!(green.name, "green"); assert_eq!(green.hex, "#00FF00"); diff --git a/exercises/variables/variables1.rs b/exercises/variables/variables1.rs index 4a3af73c..aca6677a 100644 --- a/exercises/variables/variables1.rs +++ b/exercises/variables/variables1.rs @@ -6,9 +6,7 @@ // even after you already figured it out. If you got everything working and // feel ready for the next exercise, remove the `I AM NOT DONE` comment below. -// I AM NOT DONE - fn main() { - x = 5; + let x:u32 = 5; println!("x has the value {}", x); } diff --git a/exercises/variables/variables2.rs b/exercises/variables/variables2.rs index 7774a8fb..434f17ea 100644 --- a/exercises/variables/variables2.rs +++ b/exercises/variables/variables2.rs @@ -1,10 +1,8 @@ // variables2.rs // Make me compile! Execute the command `rustlings hint variables2` if you want a hint :) -// I AM NOT DONE - fn main() { - let x; + let x:u32 = 0; if x == 10 { println!("Ten!"); } else { diff --git a/exercises/variables/variables3.rs b/exercises/variables/variables3.rs index 30ec48ff..048368dd 100644 --- a/exercises/variables/variables3.rs +++ b/exercises/variables/variables3.rs @@ -1,10 +1,8 @@ // variables3.rs // Make me compile! Execute the command `rustlings hint variables3` if you want a hint :) -// I AM NOT DONE - fn main() { - let x = 3; + let mut x:u32 = 3; println!("Number {}", x); x = 5; // don't change this line println!("Number {}", x); diff --git a/exercises/variables/variables4.rs b/exercises/variables/variables4.rs index 77f1e9ab..3c9433ad 100644 --- a/exercises/variables/variables4.rs +++ b/exercises/variables/variables4.rs @@ -1,9 +1,7 @@ // variables4.rs // Make me compile! Execute the command `rustlings hint variables4` if you want a hint :) -// I AM NOT DONE - fn main() { - let x: i32; + let x: i32 = 2; println!("Number {}", x); } diff --git a/exercises/variables/variables5.rs b/exercises/variables/variables5.rs index 5b2c2fa3..16a856a6 100644 --- a/exercises/variables/variables5.rs +++ b/exercises/variables/variables5.rs @@ -1,11 +1,9 @@ // variables5.rs // Make me compile! Execute the command `rustlings hint variables5` if you want a hint :) -// I AM NOT DONE - fn main() { let number = "3"; // don't change this line println!("Number {}", number); - number = 3; - println!("Number {}", number); + let number2 = "3"; + println!("Number {}", number2); } diff --git a/exercises/variables/variables6.rs b/exercises/variables/variables6.rs index 98666914..2c22e11a 100644 --- a/exercises/variables/variables6.rs +++ b/exercises/variables/variables6.rs @@ -1,9 +1,7 @@ // variables6.rs // Make me compile! Execute the command `rustlings hint variables6` if you want a hint :) -// I AM NOT DONE - -const NUMBER = 3; +const NUMBER:u32 = 3; fn main() { println!("Number {}", NUMBER); }