All problems
Simplify Fraction
Problem
Reduce the fraction num/den and return it as [numerator, denominator] with a positive denominator.
Divide both parts by their greatest common divisor and move any minus sign to the numerator. Zero is returned as [0, 1].
Hint
Normalise the sign after dividing by the GCD so the denominator is always positive.
Test cases
case 1
in: [8,12]
expected: [2,3]
case 2
in: [4,-6]
expected: [-2,3]
case 3
in: [-3,-9]
expected: [1,3]
case 4
in: [0,5]
expected: [0,1]
case 5
in: [7,1]
expected: [7,1]
Starter codePython
def simplify_fraction(num, den):
# Your code here
pass5 test cases · run your code against them in the editor