Skip to content

Commit 6383a3c

Browse files
committed
updates
1 parent 69073a3 commit 6383a3c

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

exercises/01_intro/01_syntax/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ mod tests {
1616
fn case() {
1717
assert_eq!(compute(1, 2), 5);
1818
}
19-
}
19+
}

exercises/02_basic_calculator/02_variables/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn speed(start: u32, end: u32, time_elapsed: u32) -> u32 {
1010
// Do you need to annotate the type of `distance`? Why or why not?
1111

1212
let distance = end - start;
13-
13+
1414
// Don't change the line below
1515
distance / time_elapsed
1616
}

exercises/02_basic_calculator/03_if_else/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/// Return `true` if `n` is even, `false` otherwise.
22
fn is_even(n: u32) -> bool {
3-
todo!()
3+
if n % 2 == 0 {
4+
true
5+
} else {
6+
false
7+
}
48
}
59

610
#[cfg(test)]

exercises/02_basic_calculator/04_panics/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
fn speed(start: u32, end: u32, time_elapsed: u32) -> u32 {
44
// TODO: Panic with a custom message if `time_elapsed` is 0
55

6+
if time_elapsed == 0 {
7+
panic!("The journey took no time at all, that's impossible!")
8+
}
9+
610
(end - start) / time_elapsed
711
}
812

exercises/02_basic_calculator/05_factorial/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
//
1111
// Use only what you learned! No loops yet, so you'll have to use recursion!
1212

13+
fn factorial(n: u32) -> u32 {
14+
if n == 0 {
15+
1
16+
} else {
17+
n * factorial(n - 1)
18+
}
19+
}
20+
1321
#[cfg(test)]
1422
mod tests {
1523
use crate::factorial;

0 commit comments

Comments
 (0)