Write a function which reduces fractions to their simplest form! Fractions will be presented as an array/tuple (depending on the language), and the reduced fraction must be returned as an array/tuple:

```
input:   [numerator, denominator]
output:  [newNumerator, newDenominator]
example: [45, 120] --> [3, 8]
```

All numerators and denominators will be positive integers.

Note: This is an introductory Kata for a series... coming soon!

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Complete search

Starter code: def reduce_fraction(fraction):
	

Solutions:
from fractions import Fraction

def reduce_fraction(fraction):
	t = Fraction(*fraction)
	return (t.numerator, t.denominator)


def gcd(a, b):
	return a if b == 0 else gcd(b, a % b)

def reduce_fraction(fraction):
	(num, denom) = fraction
	gcd_num_denom = gcd(num, denom)
	return (num // gcd_num_denom, denom // gcd_num_denom)


from math import gcd

def reduce_fraction(fraction):
	g = gcd(*fraction)
	return tuple((n // g for n in fraction))


def gcd(a, b):
	if not a % b:
		return b
	else:
		return gcd(b, a % b)

def reduce_fraction(fraction):
	return tuple((int(x / gcd(*fraction)) for x in fraction))


from math import gcd

def reduce_fraction(fraction):
	(numerator, denominator) = fraction
	d = gcd(numerator, denominator)
	return (numerator // d, denominator // d)


def reduce_fraction(fraction):
	(num, denom) = fraction
	for x in range(2, min(num, denom) + 1):
		while num % x == denom % x == 0:
			num //= x
			denom //= x
		if x > min(num, denom):
			break
	return (num, denom)


def mcd(fraccion):
	if fraccion[0] % fraccion[1] == 0:
		return fraccion[1]
	else:
		return mcd((fraccion[1], fraccion[0] % fraccion[1]))

def reduce_fraction(fraccion):
	return (fraccion[0] // mcd(fraccion), fraccion[1] // mcd(fraccion))


from math import gcd

def reduce_fraction(fraction):
	(a, b) = fraction
	g = gcd(a, b)
	return (a // g, b // g)


def reduce_fraction(fraction):
	(n1, n2) = (fraction[0], fraction[1])
	for i in range(2, 999):
		if n1 % i == 0 and n2 % i == 0:
			(n1, n2) = (n1 // i, n2 // i)
			fraction = reduce_fraction([n1, n2])
	return tuple(fraction)


def reduce_fraction(fraction):

	def get_gcd(x, y):
		a = min(x, y)
		b = max(x, y)
		if a == 0:
			return b
		return get_gcd(a, b % a)
	gcd = get_gcd(fraction[0], fraction[1])
	return tuple([int(x / gcd) for x in fraction])