Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from fractions import Fraction as f
import math
def decompose(n):
frac = f(n)
out = []
current_denom = 1
if frac >= 1:
number = int(frac)
frac -= number
out.append(str(number))
while frac > 0:
current_denom = math.ceil(1/float(frac))
candidate = f(1, current_denom)
assert candidate <= frac
frac -= candidate
out.append(str(candidate))
print(n, out)
return out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment