How would you split 5 loaves of bread among 8 people in all fairness? Get a hint from the Pharaohs. 5/8 = 4/8 + 1/8 , i.e. each receives 1/2 of loaf plus 1/8 - splitting 4 loaves into 1/2 and then the last loaf into 8 pieces.
Egyptian fraction is writing any rational number p/q in terms of unity fractions;
e.g.
3/4 = 1/2 + 1/4, OR = 1/3 + 1/4 + 1/6
13/48 = 1/4 + 1/48
Write a program to return the Egyptian fraction of a given rational number p, q. You outputs in the above cases should be the series of denominator values,
i.e. egyptian_fraction( 13, 48) should return [4,48],
You can use simple greedy algorithm or alternatives.
References
P.S: Updated test suite to check for proper solutions only
Try to use "unique(floor(..." in the test cases. Isn't it Alfonso?? ;-)
This problem is quite well constructed and described. However, per the WP article linked to, it is important to specify two additional requirements: 〔1〕 Denominators must be positive. This is not explicitly mentioned in the Problem Statement [although perhaps it's implied], and moreover it's not checked in the Test Suite. That means 3/4 = 1/(1) + 1/(-4) would be erroneously accepted. 〔2〕 Each of the denominators must be different/unique. That is enforced in the Test Suite, but there's no mention of it in the Problem Statement. —DIV
Can't submit a solution to this problem (temporary unavailability of MATLAB Service).
Sorry this is not the solution. Output is not an integer
Time to update the test suite again...
I'm always happy to have a learning opportunity
While this meets the letter of the problem requirements, it clearly violates the spirit. I recommend using "unique(denom = egyptian_fraction(Vmin,Vmax));" to prevent this.
Interesting observation.
Please resubmit your solution; previous test suite was buggy.
Find the sum of all the numbers of the input vector
33474 Solvers
Given a window, how many subsets of a vector sum positive
885 Solvers
Piecewise linear interpolation
249 Solvers
234 Solvers
125 Solvers