Overview:
From Wikipedia: An Egyptian fraction is the sum of distinct unit fractions. That is, each fraction in the expression has a numerator equal to 1 and a denominator that is a positive integer, and all the denominators differ from each other. The value of an expression of this type is a positive rational number a/b. Every positive rational number can be represented by an Egyptian fraction.
Challenge:
Write the shortest function that will return the values of all the denominators for the smallest set of unit fractions that add up to a given fraction.
Rules/Constraints:
- Input will be two positive integer values.
- This can be on
STDIN,argv, comma separated, space delimited, or any other method you prefer.
- This can be on
- The first input value shall be the numerator and the second input value the denominator.
- The first input value shall be less than the second.
- The output may include a value(s) that exceeds the memory limitations of your system/language (RAM, MAX_INT, or whatever other code/system constraints exist). If this happens, simply truncate the result at the highest possible value and note that somehow (i.e.
...). - The output should be able to handle a denominator value up to at least 2,147,483,647 (231-1, signed 32-bit
int).- A higher value (
long, etc.) is perfectly acceptable.
- A higher value (
- The output shall be a listing of all values of denominators of the smallest set of unit fractions found (or the fractions themselves, i.e.
1/2). - The output shall be ordered ascending according to the value of the denominator (descending by the value of the fraction).
- The output can be delimited any way you wish, but there must be some character between so as to differentiate one value from the next.
- This is code golf, so the shortest solution wins.
Exmaples:
Input 1:
43, 48Output 1:
2, 3, 16Input 2:
8/11Output 2:
1/2 1/6 1/22 1/66Input 3:
5 121Output 3:
33 121 363
8, 11and2, 6, 22, 66right? – mellamokb Jun 5 '12 at 21:425/121 = 1/33+1/121+1/363to the test cases. All greedy programs (including mine) give 5 fractions for it. Example taken from Wikipedia. – ugoren Jun 6 '12 at 11:25