Problem 44387. Birthday cake
It's Cody's 5th birthday, and you've been tasked with putting the candles on the cake. Your goal is to maximize the distance between the 5 required candles.
Given a rectangular cake with specified length and width, return the highest possible minimum distance between any two candles.
Important notes
- You may assume that a candle can be placed directly on the edge of the cake (even though that would be physically challenging!).
- Required tolerance: <0.01
Solution Stats
Problem Comments
-
17 Comments
The Test Suite has the highest minDist as 16 for a cake of size 16×32, but I am getting 16.564. Likewise for a couple of other sizes.
Thanks for the feedback, David. You are absolutely correct. I will fix the test suite.
Ok, I have updated the result for tests 3 and 7. Also, I changed the requirement from 3 decimal places to 2 so that minor discrepancies aren't as big an issue. Please let me know if you catch any other errors.
Thanks. I think it's all good now :-)
well, this was harder than I was anticipating :)
It might be advisable to include additional test cases to avoid hard-coded & non-general 'solutions'. Some additional cases are reported in Solution 1299656.
I second David's suggestion
I agree, David. I'll expand the test suite today.
great! one suggestion would be to add some cases with cake sides ratios between .45 and .55 but different than .5 to avoid solutions that hard-code the .5 case? (e.g. birthdaycandles(5,11) = 5.5204 ; birthdaycandles(12,23) = 12.2028). The behavior in that range seems most interesting, as the solution space seems to transition smoothly between the two "stable" configurations
Done. Thanks for helping me refine things further, Alfonso.
The last two cases have a solution of 258.83 and 517.65, I am getting 258.82 and 517.64 respectively. Is this intended and I am wrong? or is it just numerical roundoff?
I agree with Daniel Turizo that the round-off is wrong for the two last cases. I had to introduce a fudge factor of 1.00003 to get the value in the test suite, even though I use an analytical solution.
That right. I am also using an analytical solution and I had to introduce that ugly 1.0003 factor too.
Daniel and Are, thanks for the input. I modified the requirements so that the player should not need to round to 2 decimal places anymore. The "correct" answers now have higher precision, and a solution's answer must be within a tolerance of 0.01. With this format, you should not need the fudge factor you were using (either way, at least one of your submissions should work!).
I am getting 517.6381 for test #23 (same value using algebraic formula or 1d optimization) compared to the testsuite 517.6500 value, could you please double-check?
Good catch. Test suite updated.
Too many math answers on this one. Let's see some simulations, people!
Solution Comments
Show commentsProblem Recent Solvers96
Suggested Problems
-
Read a column of numbers and interpolate missing data
2280 Solvers
-
1300 Solvers
-
Rotate input square matrix 90 degrees CCW without rot90
612 Solvers
-
Given a matrix, swap the 2nd & 3rd columns
1068 Solvers
-
Highly divisible triangular number (inspired by Project Euler 12)
110 Solvers
More from this Author44
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!