Cody

# Problem 2126. Split bread like the Pharaohs - Egyptian fractions and greedy algorithm

Solution 1623470

Submitted on 7 Sep 2018 by Jens Kjærgaard Boldsen
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
% Updated test suite to remove trivial solutions; % Small Vmin = 10; Vmax = 55; denom = floor(unique(egyptian_fraction(Vmin,Vmax))); egyptian_value = sum(1./denom); rel_tol = Vmin/Vmax*1e-6; actual_error = abs( egyptian_value - Vmin/Vmax ); assert(isequal(actual_error < rel_tol ,true))

ans = 0.1818 denoms = 6 66 ans = 0.1818

2   Pass
% Pie Vmin = 113; Vmax = 355; denom = floor(unique(egyptian_fraction(Vmin,Vmax))); egyptian_value = sum(1./denom); rel_tol = Vmin/Vmax*1e-6; actual_error = abs( egyptian_value - Vmin/Vmax ); assert(isequal(actual_error < rel_tol ,true))

ans = 0.3183 denoms = 4 15 609 864780 ans = 0.3183

3   Pass
% Ramanujan Vmin = 1023; Vmax = 1729; denom = floor(unique(egyptian_fraction(Vmin,Vmax))); egyptian_value = sum(1./denom); rel_tol = Vmin/Vmax*1e-6; actual_error = abs( egyptian_value - Vmin/Vmax ); assert(isequal(actual_error < rel_tol ,true))

ans = 0.5917 denoms = 2 11 1312 4990586 ans = 0.5917

4   Pass
% E Vmin = 27; Vmax = 183; denom = floor(unique(egyptian_fraction(Vmin,Vmax))); egyptian_value = sum(1./denom); rel_tol = Vmin/Vmax*1e-6; actual_error = abs( egyptian_value - Vmin/Vmax ); assert(isequal(actual_error < rel_tol ,true))

ans = 0.1475 denoms = 7 214 91378 ans = 0.1475