From 5e8bb85aed1c50a018c19efc55372e4e3c98de4f Mon Sep 17 00:00:00 2001 From: Toby Devlin Date: Mon, 10 Feb 2020 21:52:17 +0000 Subject: [PATCH 1/3] first steps --- exercises/variables/variables1.rs | 3 +-- exercises/variables/variables2.rs | 3 +-- exercises/variables/variables3.rs | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/exercises/variables/variables1.rs b/exercises/variables/variables1.rs index 4a3af73c08..149d5ce8fa 100644 --- a/exercises/variables/variables1.rs +++ b/exercises/variables/variables1.rs @@ -6,9 +6,8 @@ // 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 = 5; println!("x has the value {}", x); } diff --git a/exercises/variables/variables2.rs b/exercises/variables/variables2.rs index 7774a8fb83..7699b86077 100644 --- a/exercises/variables/variables2.rs +++ b/exercises/variables/variables2.rs @@ -1,10 +1,9 @@ // 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 = 32; if x == 10 { println!("Ten!"); } else { diff --git a/exercises/variables/variables3.rs b/exercises/variables/variables3.rs index 07b1a52118..8453bc4e52 100644 --- a/exercises/variables/variables3.rs +++ b/exercises/variables/variables3.rs @@ -1,10 +1,9 @@ // 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 = 3; println!("Number {}", x); x = 5; println!("Number {}", x); From 1040b56ce3d124c2a96de14b4b8331798f4eb3a4 Mon Sep 17 00:00:00 2001 From: Toby Devlin Date: Mon, 10 Feb 2020 22:14:01 +0000 Subject: [PATCH 2/3] functions and variables. done them. --- exercises/functions/functions1.rs | 5 ++++- exercises/functions/functions2.rs | 3 +-- exercises/functions/functions3.rs | 3 +-- exercises/functions/functions4.rs | 3 +-- exercises/functions/functions5.rs | 3 +-- exercises/if/if1.rs | 5 ++++- exercises/test1.rs | 8 ++++++-- exercises/test2.rs | 21 ++++++++++----------- exercises/variables/variables4.rs | 3 +-- 9 files changed, 29 insertions(+), 25 deletions(-) diff --git a/exercises/functions/functions1.rs b/exercises/functions/functions1.rs index 3112527878..d994f79ecc 100644 --- a/exercises/functions/functions1.rs +++ b/exercises/functions/functions1.rs @@ -1,8 +1,11 @@ // functions1.rs // Make me compile! Execute `rustlings hint functions1` for hints :) -// I AM NOT DONE fn main() { call_me(); } + +fn call_me(){ + println!("i was called!") +} \ No newline at end of file diff --git a/exercises/functions/functions2.rs b/exercises/functions/functions2.rs index 108ba38bdf..fd72c3b45e 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: i32) { for i in 0..num { println!("Ring! Call number {}", i + 1); } diff --git a/exercises/functions/functions3.rs b/exercises/functions/functions3.rs index e3c1bf732e..70a77c4ff4 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(31); } fn call_me(num: i32) { diff --git a/exercises/functions/functions4.rs b/exercises/functions/functions4.rs index 6bf46f082b..f30af8e18f 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 (money unit) off, but if it's an odd number, it's 3 (money unit) less. -// 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 d22aa6c8b9..3f91f34f8f 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; + return num * num; } diff --git a/exercises/if/if1.rs b/exercises/if/if1.rs index 90867545ca..621ea6d5a8 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,10 @@ pub fn bigger(a: i32, b: i32) -> i32 { // - another function call // - additional variables // Execute `rustlings hint if1` for hints + if a > b { + return a; + }; + b } // Don't mind this for now :) diff --git a/exercises/test1.rs b/exercises/test1.rs index 3e13ce5567..734b0a4a66 100644 --- a/exercises/test1.rs +++ b/exercises/test1.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(num_apples: i32) -> i32 { + if num_apples <= 40 { + return num_apples * 2; + } + return num_apples * 1; +} // Don't modify this function! #[test] diff --git a/exercises/test2.rs b/exercises/test2.rs index d01606c137..60548f8d4d 100644 --- a/exercises/test2.rs +++ b/exercises/test2.rs @@ -7,7 +7,6 @@ // you think each value is. That is, add either `string_slice` or `string` // before the parentheses on each line. If you're right, it will compile! -// I AM NOT DONE fn string_slice(arg: &str) { println!("{}", arg); @@ -17,14 +16,14 @@ fn string(arg: String) { } fn main() { - ("blue"); - ("red".to_string()); - (String::from("hi")); - ("rust is fun!".to_owned()); - ("nice weather".into()); - (format!("Interpolation {}", "Station")); - (&String::from("abc")[0..1]); - (" hello there ".trim()); - ("Happy Monday!".to_string().replace("Mon", "Tues")); - ("mY sHiFt KeY iS sTiCkY".to_lowercase()); + string_slice("blue"); + string("red".to_string()); + string(String::from("hi")); + string("rust is fun!".to_owned()); + string("nice weather".into()); + string(format!("Interpolation {}", "Station")); + string_slice(&String::from("abc")[0..1]); + string_slice(" hello there ".trim()); + string("Happy Monday!".to_string().replace("Mon", "Tues")); + string("mY sHiFt KeY iS sTiCkY".to_lowercase()); } diff --git a/exercises/variables/variables4.rs b/exercises/variables/variables4.rs index 77f1e9ab01..737ac1688f 100644 --- a/exercises/variables/variables4.rs +++ b/exercises/variables/variables4.rs @@ -1,9 +1,8 @@ // 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 = 32; println!("Number {}", x); } From 17f87fbb082f0c55d8a9cca48287e8a4df2a94ee Mon Sep 17 00:00:00 2001 From: Toby Devlin Date: Mon, 10 Feb 2020 22:17:13 +0000 Subject: [PATCH 3/3] start on enums! --- exercises/enums/enums1.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/exercises/enums/enums1.rs b/exercises/enums/enums1.rs index a2223d3338..2875de4413 100644 --- a/exercises/enums/enums1.rs +++ b/exercises/enums/enums1.rs @@ -1,11 +1,13 @@ // enums1.rs // Make me compile! Execute `rustlings hint enums1` for hints! -// I AM NOT DONE #[derive(Debug)] enum Message { - // TODO: define a few types of messages as used below + Quit, + Echo, + Move, + ChangeColor } fn main() {