Cody

# Problem 44387. Birthday cake

Solution 2633329

Submitted on 30 Jun 2020 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
len = 1; wid = 1; d_correct = 0.7071; assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 1 h = 1 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 0.7071

2   Pass
len = 2; wid = 3; d_correct = 1.8028; assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 3 h = 2 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 1.8028

3   Pass
len = 3; wid = 8; d_correct = 3.6056; assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 8 h = 3 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 3.6056

4   Pass
len = 4; wid = 3; d_correct = 2.5000; assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 4 h = 3 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 2.5000

5   Pass
len = 5; wid = 4; d_correct = 3.2016; assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 5 h = 4 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 3.2016

6   Pass
len = 5; wid = 6; d_correct = 3.9051; assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 6 h = 5 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 3.9051

7   Pass
len = 5; wid = 11; d_correct = 5.5200; assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 11 h = 5 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 5.5203

8   Pass
len = 7; wid = 6; d_correct = 4.6098; assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 7 h = 6 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 4.6098

9   Pass
len = 8; wid = 7; d_correct = 5.3151; assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 8 h = 7 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 5.3151

10   Pass
len = 8; wid = 9; d_correct = 6.0208; assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 9 h = 8 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 6.0208

11   Pass
len = 10; wid = 9; d_correct = 6.7268; assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 10 h = 9 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 6.7268

12   Pass
len = 11; wid = 10; d_correct = 7.4330; assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 11 h = 10 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 7.4330

13   Pass
len = 12; wid = 23; d_correct = 12.2018; assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 23 h = 12 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 12.2028

14   Pass
len = 15; wid = 32; d_correct = 16.1616; assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 32 h = 15 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 16.1623

15   Pass
len = 16; wid = 32; d_correct = 16.5644; assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 32 h = 16 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 16.5644

16   Pass
len = 17; wid = 32; d_correct = 17.1902; assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 32 h = 17 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 17.1909

17   Pass
len = 64; wid = 1; d_correct = 16.0312; assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 64 h = 1 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 16.0312

18   Pass
len = 36; wid = 36; d_correct = 25.4558; assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 36 h = 36 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 25.4558

19   Pass
len = 48; wid = 24; d_correct = 24.8466; assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 48 h = 24 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 24.8466

20   Pass
len = 26; wid = 48; d_correct = 26.1679; assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 48 h = 26 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 26.1687

21   Pass
len = 100.25; wid = 100.25; d_correct = 70.8875; assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 100.2500 h = 100.2500 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 70.8875

22   Pass
len = 500; wid = 250; d_correct = 258.8190; assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 500 h = 250 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 258.8190

23   Pass
len = 500; wid = 1000; d_correct = 517.6381; assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 1000 h = 500 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 517.6381

24   Pass
len = randi([1,1e4]); wid = len; d_correct = sqrt((len/2)^2+(wid/2)^2); assert(abs(birthdaycandles(len,wid)-d_correct)<1e-2)

w = 9531 h = 9531 g = function_handle with value: @(x,y)min(cat(3,repmat((w*x).^2+h^2,numel(y),1),repmat((w*.5).^2+(h*y).^2,1,numel(x)),(w.*(.5-x)).^2+(h*(1-y)).^2,repmat(((w.*(1-2*x)).^2),numel(y),1)),[],3) d = 6.7394e+03

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!