Google for Developers always has interesting puzzles to stay focused on what is crucial in #ComputerScience: #logic.
From my point of view, the question from the video below is about the interpretation of definitions and restrictions. There are different possibilities to define something as "equal", so the solution is very likely to be about how to slice the cake by exploiting what was NOT given in the question as a restriction.
1. Nobody said that the pieces of the cake need to have the same shape. By just focusing on volume equality of the resulting slices, the solution is to (1) cut one small piece from one side and put it aside before (2) slicing the remaining cake into two pieces of equal shapes. (Shape equality: false. Layer equality: true. Volume equality: true. Cuts: 2.)
2. Nobody said that the slicing needs to be done vertically from top to bottom. Thinking the cake in layers adds a new degree of freedom, ensuring even shape equality at the cost of separating possible ingredient levels from each other. If the cake has a height of, say, 6 centimetres, (1) the first cut should be made horizontally 2 centimetres from the top — i.e. 4 centimetres from the bottom — and (2) the final cut would be again horizontally 2 centimetres from the new top — i.e. 2 centimetres from the original bottom. The downside of this approach is that, if the cake would consist of a dough base, some fruit filling, and finally some decoration, one person would receive the dough base, one the fruit filling and the third person only the decorations. But maybe these guests would even prefer this approach! 😋 (Shape equality: true. Layer equality: false. Volume equality: true. Cuts: 2.)
3. Nobody said that only one (standard) knife needs to be employed — or that the used knife must keep its shape. This is a rather mean trick with (at least) three flavours: (a) welding three blades together with an angle of 120⁰ from each other and mounting this tool at one central handle gives a super-knife to cut perfect thirds from a cylindric cake with only one cut maintaining shape, volume, and layer equality. (b) The next option is to bring an own knife with a long, bended blade (angle: 120⁰ or 240⁰, depending on the perspective) to (1) cut the cake from its centre towards its edge with a standard knife and (2) finally again with the bended knife while paying attention to ensuring an angle of 120⁰ to previous cut to, again, create shape, volume, and layer equality. (c) This is the meanest trick of all, assuming an appropriate blade length of the used knife: if an own knife should not be allowed, proceeding as in (b) works as well — as long as the knife's blade is bended appropriately between the two cuts to create shape, volume, and layer equality.
None of these approaches requires asking a further question at all.
In this week’s developer challenge, it’s not just about cutting the cake—it’s about asking the right questions first. 🍰 What follow-up questions would you ask before making your two cuts?
Software Engineer
2moHas to be carefully planned & timeboxed depending on circumstances and scale - I've also seen some of the opposite - many partial attempts scattered across the codebase, started and never finished by devs who're no longer around. Extreme cases aside, I honestly tend to prefer consistent "good enough" solutions nowadays and cut the cognitive load of having multiple "awesome" styles.