From f61b3a9e90a55783f7d930ea64cc2ac79683595b Mon Sep 17 00:00:00 2001 From: mmo Date: Fri, 26 Aug 2022 12:01:03 +0200 Subject: [PATCH] add solutions --- exercises/if/if1.rs | 5 +---- exercises/primitive_types/primitive_types3.rs | 3 +-- exercises/primitive_types/primitive_types4.rs | 3 +-- exercises/primitive_types/primitive_types5.rs | 3 +-- exercises/primitive_types/primitive_types6.rs | 3 +-- exercises/vecs/vecs1.rs | 8 ++++++-- 6 files changed, 11 insertions(+), 14 deletions(-) diff --git a/exercises/if/if1.rs b/exercises/if/if1.rs index 70b49d57..ea634add 100644 --- a/exercises/if/if1.rs +++ b/exercises/if/if1.rs @@ -11,11 +11,8 @@ pub fn bigger(a: i32, b: i32) -> i32 { if a > b { a } - else if b > a { - b - } else { - a + b } } diff --git a/exercises/primitive_types/primitive_types3.rs b/exercises/primitive_types/primitive_types3.rs index fa7d019a..421acaed 100644 --- a/exercises/primitive_types/primitive_types3.rs +++ b/exercises/primitive_types/primitive_types3.rs @@ -2,10 +2,9 @@ // Create an array with at least 100 elements in it where the ??? is. // Execute `rustlings hint primitive_types3` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE fn main() { - let a = ??? + let a = [0;100]; 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 71fa243c..0b6d85f5 100644 --- a/exercises/primitive_types/primitive_types4.rs +++ b/exercises/primitive_types/primitive_types4.rs @@ -2,13 +2,12 @@ // Get a slice out of Array a where the ??? is so that the test passes. // Execute `rustlings hint primitive_types4` or use the `hint` watch subcommand for a hint. -// 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 4fd9141f..76a92b88 100644 --- a/exercises/primitive_types/primitive_types5.rs +++ b/exercises/primitive_types/primitive_types5.rs @@ -2,11 +2,10 @@ // Destructure the `cat` tuple so that the println will work. // Execute `rustlings hint primitive_types5` or use the `hint` watch subcommand for a hint. -// 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 ddf8b423..c35d4625 100644 --- a/exercises/primitive_types/primitive_types6.rs +++ b/exercises/primitive_types/primitive_types6.rs @@ -3,13 +3,12 @@ // You can put the expression for the second element where ??? is so that the test passes. // Execute `rustlings hint primitive_types6` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE #[test] fn indexing_tuple() { let numbers = (1, 2, 3); // Replace below ??? with the tuple indexing syntax. - let second = ???; + let second = numbers.1; assert_eq!(2, second, "This is not the 2nd number in the tuple!") diff --git a/exercises/vecs/vecs1.rs b/exercises/vecs/vecs1.rs index 4e8c4cbb..db360b17 100644 --- a/exercises/vecs/vecs1.rs +++ b/exercises/vecs/vecs1.rs @@ -4,11 +4,15 @@ // Make me compile and pass the test! // Execute `rustlings hint vecs1` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE fn array_and_vec() -> ([i32; 4], Vec) { let a = [10, 20, 30, 40]; // a plain array - let v = // TODO: declare your vector here with the macro for vectors + + let mut v = Vec::new(); + + for i in a { + v.push(i); + } (a, v) }