mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-10 04:39:18 +00:00
add solutions
This commit is contained in:
parent
a40913fcd4
commit
f61b3a9e90
@ -11,11 +11,8 @@ pub fn bigger(a: i32, b: i32) -> i32 {
|
|||||||
if a > b {
|
if a > b {
|
||||||
a
|
a
|
||||||
}
|
}
|
||||||
else if b > a {
|
|
||||||
b
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
a
|
b
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,10 +2,9 @@
|
|||||||
// Create an array with at least 100 elements in it where the ??? is.
|
// 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.
|
// Execute `rustlings hint primitive_types3` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let a = ???
|
let a = [0;100];
|
||||||
|
|
||||||
if a.len() >= 100 {
|
if a.len() >= 100 {
|
||||||
println!("Wow, that's a big array!");
|
println!("Wow, that's a big array!");
|
||||||
|
|||||||
@ -2,13 +2,12 @@
|
|||||||
// Get a slice out of Array a where the ??? is so that the test passes.
|
// 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.
|
// Execute `rustlings hint primitive_types4` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn slice_out_of_array() {
|
fn slice_out_of_array() {
|
||||||
let a = [1, 2, 3, 4, 5];
|
let a = [1, 2, 3, 4, 5];
|
||||||
|
|
||||||
let nice_slice = ???
|
let nice_slice = &a[1..4];
|
||||||
|
|
||||||
assert_eq!([2, 3, 4], nice_slice)
|
assert_eq!([2, 3, 4], nice_slice)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,11 +2,10 @@
|
|||||||
// Destructure the `cat` tuple so that the println will work.
|
// Destructure the `cat` tuple so that the println will work.
|
||||||
// Execute `rustlings hint primitive_types5` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint primitive_types5` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let cat = ("Furry McFurson", 3.5);
|
let cat = ("Furry McFurson", 3.5);
|
||||||
let /* your pattern here */ = cat;
|
let (name, age) = cat;
|
||||||
|
|
||||||
println!("{} is {} years old.", name, age);
|
println!("{} is {} years old.", name, age);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,13 +3,12 @@
|
|||||||
// You can put the expression for the second element where ??? is so that the test passes.
|
// 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.
|
// Execute `rustlings hint primitive_types6` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn indexing_tuple() {
|
fn indexing_tuple() {
|
||||||
let numbers = (1, 2, 3);
|
let numbers = (1, 2, 3);
|
||||||
// Replace below ??? with the tuple indexing syntax.
|
// Replace below ??? with the tuple indexing syntax.
|
||||||
let second = ???;
|
let second = numbers.1;
|
||||||
|
|
||||||
assert_eq!(2, second,
|
assert_eq!(2, second,
|
||||||
"This is not the 2nd number in the tuple!")
|
"This is not the 2nd number in the tuple!")
|
||||||
|
|||||||
@ -4,11 +4,15 @@
|
|||||||
// Make me compile and pass the test!
|
// Make me compile and pass the test!
|
||||||
// Execute `rustlings hint vecs1` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint vecs1` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn array_and_vec() -> ([i32; 4], Vec<i32>) {
|
fn array_and_vec() -> ([i32; 4], Vec<i32>) {
|
||||||
let a = [10, 20, 30, 40]; // a plain array
|
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)
|
(a, v)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user