Skip to content

Instantly share code, notes, and snippets.

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
while frac > 0:
current_denom = math.ceil(1/float(frac))
candidate = f(1, current_denom)
assert candidate <= frac
frac -= candidate
print(n, out)
return out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment