Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions exercises/decimal/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ impl Decimal {
&lower_precision.digits * pow(BigInt::from(10_usize), precision_difference);
lower_precision.decimal_index += precision_difference;
}
if one.decimal_index < two.decimal_index {
expand(&mut one, &two)
} else if one.decimal_index > two.decimal_index {
expand(&mut two, &one)
match one.decimal_index.cmp(&two.decimal_index) {
std::cmp::Ordering::Equal => {},
std::cmp::Ordering::Less => expand(&mut one, &two),
std::cmp::Ordering::Greater => expand(&mut two, &one),
}
assert_eq!(one.decimal_index, two.decimal_index);
}
Expand Down
16 changes: 8 additions & 8 deletions exercises/palindrome-products/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ pub fn palindrome_products(min: u64, max: u64) -> Option<(Palindrome, Palindrome
result = match result {
None => Some((Palindrome::new(a, b), Palindrome::new(a, b))),
Some((mut minp, mut maxp)) => {
if a * b < minp.value() {
minp = Palindrome::new(a, b);
} else if a * b == minp.value() {
minp.insert(a, b);
match (a * b).cmp(&minp.value()) {
std::cmp::Ordering::Greater => {},
std::cmp::Ordering::Less => minp = Palindrome::new(a, b),
std::cmp::Ordering::Equal => minp.insert(a, b),
}
if a * b > maxp.value() {
maxp = Palindrome::new(a, b);
} else if a * b == maxp.value() {
maxp.insert(a, b);
match (a * b).cmp(&maxp.value()) {
std::cmp::Ordering::Less => {},
std::cmp::Ordering::Greater => maxp = Palindrome::new(a, b),
std::cmp::Ordering::Equal => maxp.insert(a, b),
}
Some((minp, maxp))
}
Expand Down
10 changes: 4 additions & 6 deletions exercises/perfect-numbers/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ pub fn classify(num: u64) -> Option<Classification> {
return None;
}
let sum: u64 = (1..num).filter(|i| num % i == 0).sum();
if sum == num {
Some(Classification::Perfect)
} else if sum < num {
Some(Classification::Deficient)
} else {
Some(Classification::Abundant)
match sum.cmp(&num) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice that putting this whole thing in a Some is possible, but right now we are just rewriting ifs, not doing that.

std::cmp::Ordering::Equal => Some(Classification::Perfect),
std::cmp::Ordering::Less => Some(Classification::Deficient),
std::cmp::Ordering::Greater => Some(Classification::Abundant),
}
}

Expand Down