BabenkoA / CodeWarsTest

CodeWars methods
0 stars 0 forks source link

Some Egyptian fractions #14

Closed BabenkoA closed 3 years ago

BabenkoA commented 3 years ago

decompose this number as a sum of rationals with numerators equal to one and without repetitions (2/3 = 1/2 + 1/6 is correct but not 2/3 = 1/3 + 1/3, 1/3 is repeated).

The algorithm must be "greedy", so at each stage the new rational obtained in the decomposition must have a denominator as small as possible. In this manner the sum of a few fractions in the decomposition gives a rather good approximation of the rational to decompose.

2/3 = 1/3 + 1/3 doesn't fit because of the repetition but also because the first 1/3 has a denominator bigger than the one in 1/2 in the decomposition 2/3 = 1/2 + 1/6.

decompose("21/23") or "21" "23" or 21/23 should return

["1/2", "1/3", "1/13", "1/359", "1/644046"]

BabenkoA commented 3 years ago

create method and test cases