Skip to content

Commit

Permalink
refactor slightly + add concepts & difficulty to the practice in config
Browse files Browse the repository at this point in the history
  • Loading branch information
Nenad committed Jul 3, 2024
1 parent 1464a5b commit 778261c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 6 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,13 @@
"slug": "rational-numbers",
"name": "Rational Numbers",
"uuid": "9858a357-b935-437d-b4e0-c3aac20859cf",
"practices": [],
"practices": [
"operator-overload",
"mutability",
"integers"
],
"prerequisites": [],
"difficulty": 1
"difficulty": 3
}
],
"foregone": [
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/rational-numbers/.meta/example.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ impl RationalPow of RationalPowTrait {
if *self.numer == 0 {
return *self;
};
// fast_power works only with unsigned integers

let power_abs = abs(power);

// determine the new number's sign
let sign: i128 = if *self.numer < 0 && power_abs % 2 == 1 {
-1
Expand All @@ -106,8 +107,8 @@ impl RationalPow of RationalPowTrait {
}

fn rpow(self: @u128, power: Rational) -> u128 {
// Cairo does not support floating point numbers, so a negative rational number
// will always return the result 0 (as 1 divided by any number is 0 in Cairo)
// Cairo only supports integers, so a negative rational exponent
// will always return the result 0
if power.numer < 0 {
return 0;
};
Expand Down

0 comments on commit 778261c

Please sign in to comment.