diff --git a/config.json b/config.json index ea18f589..0c490ade 100644 --- a/config.json +++ b/config.json @@ -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": [ diff --git a/exercises/practice/rational-numbers/.meta/example.cairo b/exercises/practice/rational-numbers/.meta/example.cairo index ceb1bb8e..26d32a6d 100644 --- a/exercises/practice/rational-numbers/.meta/example.cairo +++ b/exercises/practice/rational-numbers/.meta/example.cairo @@ -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 @@ -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; };