# [Community Puzzle] Should Bakers be Frugal?

Coding Games and Programming Challenges to Code Better

Created by @Lisa-Has-Ideas,validated by @blasterpoard,@TBali and @FredericLocquet.
If you have any issues, feel free to ping them.

Really nice Puzzle. Well written and easy to understand with a real-life context !

2 Likes

(Thanks for the posting)

Maybe Iâ€™m misunderstand something here.
After the first step, the total dough is only enough, to make only one doughsquare (side=1.389) that is big enough for one more biscuit. How can the solution then be â€ś2â€ť ?

1 Like

Hi Hackintosh â€“
Thanks for playing. You are definitely on the right track, and good question.

After the baker cuts out the one biscuit from the 1.389 side â€śDoughSquareâ€ť, then what is left of the dough, and what can be done with what is left.
(Iâ€™m trying to make this vague, while still giving some hint/direction.)

Does that help? If not, feel free to message me.

The last pastry is a particular case. Having enough dough may not be sufficient. Check the prompt of the exercice, youâ€™ll figure it out ^^

I canâ€™t figure out how to develop a formula for the number of biscuits a frugal baker would make. Any tips for how I could do this?

Apparently I cannot pass the last validator (#14 â€śA gazillion micro-biscuits Validatorâ€ť), even if I can pass the same test in the IDE.

Hi TGGO â€“

I donâ€™t want to be too clear in this answer, but here are some vague unrelated comments that might get you going:

You want to do something WHILE you can. You want to cut out biscuits while the square is big enough

â€śNegative spaceâ€ť (in art) is the idea of looking not at the object (biscuit) itself, but at the space around it.

Imagine an ideal scenario where the frugal baker is the most frugal he can possibly be, how much wasted dough is left at the end? (Itâ€™s not zero.) If you know this answer, then you can determine the actual usable dough and get a formula from that.

I hope that helps. Thanks for playing.

Interesting. I havenâ€™t heard any problems like this before. Can you send me your code, and Iâ€™ll have a look??

I have the same problem, but my case might be somewhat special:

I previously solved the puzzle in python, that worked perfectly.

Now Iâ€™m trying to solve it in pure bash for fun.
Since bash cannâ€™t handle floating point numbers, I multiply everything by a â€śjust big enoughâ€ť number to be able to work with integers. Then, to avoid overflows when calculating areas, I divide them back temporarily with another â€śjust big enoughâ€ť number which unavoidably truncates some hopefully unimportant digits from the end. â€śJust big enoughâ€ť is important because bash alone is extremely bad at arithmetics and the process can easily time out with too big numbers.

So Iâ€™m guessing the problem in my case

• might come from precision problems from rounding (truncating) errors,
• or maybe there is more than three decimal digits in some of the input numbers (which my code canâ€™t handle),
• or the initial biscuit (or dough) size is less than 0.1 (so there is a leading zero in the decimal digits, which my code currently also canâ€™t handle),
• or the process simply times outâ€¦

I could change my code to deal with the middle two (and even test it on a custom case), but thatâ€™s a lot of work to handle a case that might not even exist, and thereâ€™s still no guaranty that it will handle the actual validation test without overlow or precision errors. And since I canâ€™t see the output of the validation test, those two are indistinguishableâ€¦

It would be great if you could provide me another test case which only differs from validatior 14 in nonzero digits and have roughly the same initial side to diameter proportions as well.

Thanks for the nice puzzle and for your help!

Hi RaceBot â€”

Thanks for playing my puzzle.

Iâ€™m just going to message you Validator14 if thatâ€™s okay

1 Like

For others interested, the problem Bold Goblin had was just that the PI value used in the solution was not precise enough. It had to be more exact than 4 decimal places.

2 Likes

Hi all.

I am wondering if anybody can help me here. My code passed all tests but failed when submitted.
It wonâ€™t pass the validator#9 (Who kneads that Validator) and validator #13(Micro World Validator).

I coded this using Typescript, Javascript and Go and all have the same problem. As for the Pi I used Math.PI in Typescript and Javascript, and math.Pi in Go.

Was there anyone experiencing the same?

My solution using math.Pi works in Go so itâ€™s not a Pi accuracy problem. If you want to send me your code I can have a look?

A common mistake is that people round their intermediate results and then use the less accurate values to do further calculation. Check whether you have fallen into this trap.

Thanks guys I just resolved this issue and reached 100% completion.

Apparently, there are some mistakes in my logic to count the frugalBakerMade each iteration. Iâ€™m actually surprised my previous code was able to passed the tests.

after experimenting with the precision requirements of PI, 3.14159f substituted in for PI passes the largest case in the validators. Still, safer to stick with library provided constants

1 Like

For the record, I learned so much about donuts, biscuits and doughs while solving this puzzle lol. Real life scenarios are the coolest puzzles

1 Like

could you tell me how i can know the side length of the the new DoughSquare after i take as much biscuits as i can