The “Maybe Cake” puzzle
Here’s a programming puzzle I created, which deals with a bunch of dependent pieces of “optional” data. The idea is to model the constraints in the problem description, and resolve them in order to produce a cake. Solve it in any way you like, in whatever language. I’ve set up a template in Haskell (MaybeCake.hs), so you just have to define one function. I’ve also provided a solution (MaybeCakeAnswer.hs). The Haskell source uses the Maybe data structure, but other solutions may be possible. github repo.
Apologies if my recipes are rubbish – I’m not much of a baker Enjoy!
I’d like a cake.
Ideally, I’d like to bake it myself, but if I don’t have the ingredients, I’ll buy one from the bakery (if they have one).
I can make 2 types of cake:
- My favourite is a mud cake (egg, chocolate, flour).
- I can also make a flourless cake (egg, chocolate, cocoa).
There might be some chocolate in the fridge or the pantry.
There might be some flour in the pantry.
There might be some cocoa in the pantry.
There might be an egg in the fridge, but I’d prefer a fresh one – maybe my chook laid one?
But I think I saw a taipan around the chicken coup yesterday – hopefully he didn’t get my chook!
So, do I get a cake and, if so, which one?