Skip to content

Commit 278a1f1

Browse files
Original exercises
1 parent 1acbbb6 commit 278a1f1

27 files changed

+86
-57
lines changed

exercises/functions/functions1.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// functions1.rs
22
// Execute `rustlings hint functions1` or use the `hint` watch subcommand for a hint.
33

4+
// I AM NOT DONE
5+
46
fn main() {
57
call_me();
68
}
7-
8-
fn call_me() {
9-
println!("I'm Nidhal Messaoudi, a software developer going Rusty!!!");
10-
}

exercises/functions/functions2.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// functions2.rs
22
// Execute `rustlings hint functions2` or use the `hint` watch subcommand for a hint.
33

4+
// I AM NOT DONE
5+
46
fn main() {
57
call_me(3);
68
}
79

8-
fn call_me(num: i32) {
10+
fn call_me(num:) {
911
for i in 0..num {
1012
println!("Ring! Call number {}", i + 1);
1113
}

exercises/functions/functions3.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// functions3.rs
22
// Execute `rustlings hint functions3` or use the `hint` watch subcommand for a hint.
33

4+
// I AM NOT DONE
5+
46
fn main() {
5-
call_me(12);
7+
call_me();
68
}
79

810
fn call_me(num: u32) {

exercises/functions/functions4.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
// in the signatures for now. If anything, this is a good way to peek ahead
88
// to future exercises!)
99

10+
// I AM NOT DONE
11+
1012
fn main() {
1113
let original_price = 51;
1214
println!("Your sale price is {}", sale_price(original_price));
1315
}
1416

15-
fn sale_price(price: i32) -> i32 {
17+
fn sale_price(price: i32) -> {
1618
if is_even(price) {
1719
price - 10
1820
} else {

exercises/functions/functions5.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// functions5.rs
22
// Execute `rustlings hint functions5` or use the `hint` watch subcommand for a hint.
33

4+
// I AM NOT DONE
5+
46
fn main() {
57
let answer = square(3);
68
println!("The square of 3 is {}", answer);
79
}
810

911
fn square(num: i32) -> i32 {
10-
return num * num;
12+
num * num;
1113
}

exercises/if/if1.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
// if1.rs
22
// Execute `rustlings hint if1` or use the `hint` watch subcommand for a hint.
33

4+
// I AM NOT DONE
5+
46
pub fn bigger(a: i32, b: i32) -> i32 {
57
// Complete this function to return the bigger number!
68
// Do not use:
79
// - another function call
810
// - additional variables
9-
if a > b {
10-
a
11-
} else {
12-
b
13-
}
1411
}
1512

1613
// Don't mind this for now :)

exercises/if/if2.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
// Step 2: Get the bar_for_fuzz and default_to_baz tests passing!
55
// Execute `rustlings hint if2` or use the `hint` watch subcommand for a hint.
66

7+
// I AM NOT DONE
8+
79
pub fn foo_if_fizz(fizzish: &str) -> &str {
8-
if fizzish == "fuzz" {
9-
"bar"
10-
} else if fizzish == "fizz" {
10+
if fizzish == "fizz" {
1111
"foo"
1212
} else {
13-
"baz"
13+
1
1414
}
1515
}
1616

exercises/intro/intro1.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
// when you change one of the lines below! Try adding a `println!` line, or try changing
1010
// what it outputs in your terminal. Try removing a semicolon and see what happens!
1111

12+
// I AM NOT DONE
13+
1214
fn main() {
1315
println!("Hello and");
1416
println!(r#" welcome to... "#);

exercises/intro/intro2.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Make the code print a greeting to the world.
33
// Execute `rustlings hint intro2` or use the `hint` watch subcommand for a hint.
44

5+
// I AM NOT DONE
6+
57
fn main() {
6-
println!("Hello {}!", "World");
8+
println!("Hello {}!");
79
}

exercises/move_semantics/move_semantics1.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
// move_semantics1.rs
22
// Execute `rustlings hint move_semantics1` or use the `hint` watch subcommand for a hint.
33

4+
// I AM NOT DONE
5+
46
fn main() {
57
let vec0 = Vec::new();
68

7-
let mut vec1 = fill_vec(vec0);
9+
let vec1 = fill_vec(vec0);
810

911
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
1012

exercises/move_semantics/move_semantics2.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
// Make me compile without changing line 13 or moving line 10!
33
// Execute `rustlings hint move_semantics2` or use the `hint` watch subcommand for a hint.
44

5+
// I AM NOT DONE
6+
57
fn main() {
6-
let mut vec0 = Vec::new();
8+
let vec0 = Vec::new();
79

8-
let mut vec1 = fill_vec(&mut vec0);
10+
let mut vec1 = fill_vec(vec0);
911

1012
// Do not change the following line!
1113
println!("{} has length {} content `{:?}`", "vec0", vec0.len(), vec0);
@@ -15,12 +17,12 @@ fn main() {
1517
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
1618
}
1719

18-
fn fill_vec(vec: &mut Vec<i32>) -> Vec<i32> {
20+
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
1921
let mut vec = vec;
2022

2123
vec.push(22);
2224
vec.push(44);
2325
vec.push(66);
2426

25-
vec.to_vec()
27+
vec
2628
}

exercises/move_semantics/move_semantics3.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// (no lines with multiple semicolons necessary!)
44
// Execute `rustlings hint move_semantics3` or use the `hint` watch subcommand for a hint.
55

6+
// I AM NOT DONE
7+
68
fn main() {
79
let vec0 = Vec::new();
810

@@ -15,7 +17,7 @@ fn main() {
1517
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
1618
}
1719

18-
fn fill_vec(mut vec: Vec<i32>) -> Vec<i32> {
20+
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
1921
vec.push(22);
2022
vec.push(44);
2123
vec.push(66);

exercises/primitive_types/primitive_types1.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Fill in the rest of the line that has code missing!
33
// No hints, there's no tricks, just get used to typing these :)
44

5+
// I AM NOT DONE
6+
57
fn main() {
68
// Booleans (`bool`)
79

@@ -10,7 +12,7 @@ fn main() {
1012
println!("Good morning!");
1113
}
1214

13-
let is_evening = false; // Finish the rest of this line like the example! Or make it be false!
15+
let // Finish the rest of this line like the example! Or make it be false!
1416
if is_evening {
1517
println!("Good evening!");
1618
}

exercises/primitive_types/primitive_types2.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
// Fill in the rest of the line that has code missing!
33
// No hints, there's no tricks, just get used to typing these :)
44

5+
// I AM NOT DONE
6+
57
fn main() {
68
// Characters (`char`)
79

810
// Note the _single_ quotes, these are different from the double quotes
911
// you've been seeing around.
10-
let my_first_initial = 'N';
12+
let my_first_initial = 'C';
1113
if my_first_initial.is_alphabetic() {
1214
println!("Alphabetical!");
1315
} else if my_first_initial.is_numeric() {
@@ -16,12 +18,12 @@ fn main() {
1618
println!("Neither alphabetic nor numeric!");
1719
}
1820

19-
let my_favorite_character = '🔥'; // Finish this line like the example! What's your favorite character?
21+
let // Finish this line like the example! What's your favorite character?
2022
// Try a letter, try a number, try a special character, try a character
2123
// from a different language than your own, try an emoji!
22-
if my_favorite_character.is_alphabetic() {
24+
if your_character.is_alphabetic() {
2325
println!("Alphabetical!");
24-
} else if my_favorite_character.is_numeric() {
26+
} else if your_character.is_numeric() {
2527
println!("Numerical!");
2628
} else {
2729
println!("Neither alphabetic nor numeric!");

exercises/primitive_types/primitive_types3.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// Create an array with at least 100 elements in it where the ??? is.
33
// Execute `rustlings hint primitive_types3` or use the `hint` watch subcommand for a hint.
44

5-
fn main() {
6-
let a = ["Nidhal Messaoudi, A Rust professional!"; 100];
5+
// I AM NOT DONE
76

8-
println!("{}", a.len());
7+
fn main() {
8+
let a = ???
99

1010
if a.len() >= 100 {
1111
println!("Wow, that's a big array!");

exercises/primitive_types/primitive_types4.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
// Get a slice out of Array a where the ??? is so that the test passes.
33
// Execute `rustlings hint primitive_types4` or use the `hint` watch subcommand for a hint.
44

5+
// I AM NOT DONE
6+
57
#[test]
68
fn slice_out_of_array() {
79
let a = [1, 2, 3, 4, 5];
810

9-
let nice_slice = &a[1..4];
11+
let nice_slice = ???
1012

1113
assert_eq!([2, 3, 4], nice_slice)
1214
}

exercises/primitive_types/primitive_types5.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
// Destructure the `cat` tuple so that the println will work.
33
// Execute `rustlings hint primitive_types5` or use the `hint` watch subcommand for a hint.
44

5+
// I AM NOT DONE
6+
57
fn main() {
68
let cat = ("Furry McFurson", 3.5);
7-
let (name, age) = cat;
9+
let /* your pattern here */ = cat;
810

911
println!("{} is {} years old.", name, age);
1012
}

exercises/primitive_types/primitive_types6.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
// You can put the expression for the second element where ??? is so that the test passes.
44
// Execute `rustlings hint primitive_types6` or use the `hint` watch subcommand for a hint.
55

6+
// I AM NOT DONE
7+
68
#[test]
79
fn indexing_tuple() {
810
let numbers = (1, 2, 3);
911
// Replace below ??? with the tuple indexing syntax.
10-
let second = numbers.1;
12+
let second = ???;
1113

1214
assert_eq!(2, second,
1315
"This is not the 2nd number in the tuple!")

exercises/quiz1.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,10 @@
1010
// Write a function that calculates the price of an order of apples given
1111
// the quantity bought. No hints this time!
1212

13-
// Put your function here!
14-
fn calculate_price_of_apples(quantity: i32) -> i32 {
15-
let mut quantity= quantity;
16-
if quantity <= 40 {
17-
quantity = quantity * 2;
18-
}
19-
return quantity;
13+
// I AM NOT DONE
2014

21-
// if quantity > 40 {
22-
// quantity
23-
// } else {
24-
// quantity * 2
25-
// }
26-
}
15+
// Put your function here!
16+
// fn calculate_price_of_apples {
2717

2818
// Don't modify this function!
2919
#[test]

exercises/variables/variables1.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// Make me compile!
33
// Execute `rustlings hint variables1` or use the `hint` watch subcommand for a hint.
44

5+
// I AM NOT DONE
6+
57
fn main() {
6-
let x = 5;
8+
x = 5;
79
println!("x has the value {}", x);
810
}

exercises/variables/variables2.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// variables2.rs
22
// Execute `rustlings hint variables2` or use the `hint` watch subcommand for a hint.
33

4+
// I AM NOT DONE
5+
46
fn main() {
5-
let x = 12;
7+
let x;
68
if x == 10 {
79
println!("x is ten!");
810
} else {

exercises/variables/variables3.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// variables3.rs
22
// Execute `rustlings hint variables3` or use the `hint` watch subcommand for a hint.
33

4+
// I AM NOT DONE
5+
46
fn main() {
5-
let x: i32 = 12;
7+
let x: i32;
68
println!("Number {}", x);
79
}

exercises/variables/variables4.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// variables4.rs
22
// Execute `rustlings hint variables4` or use the `hint` watch subcommand for a hint.
33

4+
// I AM NOT DONE
5+
46
fn main() {
5-
let mut x = 3;
7+
let x = 3;
68
println!("Number {}", x);
79
x = 5; // don't change this line
810
println!("Number {}", x);

exercises/variables/variables5.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// variables5.rs
22
// Execute `rustlings hint variables5` or use the `hint` watch subcommand for a hint.
33

4+
// I AM NOT DONE
5+
46
fn main() {
57
let number = "T-H-R-E-E"; // don't change this line
68
println!("Spell a Number : {}", number);
7-
let number = 3; // don't rename this variable
9+
number = 3; // don't rename this variable
810
println!("Number plus two is : {}", number + 2);
911
}

exercises/variables/variables6.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// variables6.rs
22
// Execute `rustlings hint variables6` or use the `hint` watch subcommand for a hint.
33

4-
const NUMBER: i32 = 3;
4+
// I AM NOT DONE
5+
6+
const NUMBER = 3;
57
fn main() {
68
println!("Number {}", NUMBER);
79
}

0 commit comments

Comments
 (0)