3 ms·
Sometimes you can generalize the problem a bit to get a shorter solution.
by de_watcher 7y ago
Sometimes you can generalize the problem a bit to get a shorter solution.
- sorokod 7y agoPretty much by definition you will be covering a wider surface of possible inputs and behaviours and so acquiring complexity
- Tyr42 7y agoHere's a fun example from math which requires generalizing to get a good solution to. Suppose you have a 2^n x 2^n sized courtyard. You have one 1x1 statue, and unlimited L pieces (2x2 with a corner missing). You would like to have a layout which places the statue in one of the centermost tiles, and fill the rest with L pieces. ---------------- Solution ---------------- Define a layout function with allows for the empty tile to be in any corner. This is trivial for 2x2, as it's just an L peice. By tiling these squares, you can solve for the next size up. Put three with the hole in the center and fill in with an L piece to get the bigger square. At the end, take 4 2^(n-1) squares and put the holes in the middle. Add one L and you are done. What was the point of that? By generalizing your solve function to have more outputs, it lets you build up a structure from it, in which it's easy to solve your actual goal.
- sorokod 7y agoAnd complex analysis informs number theory. An example from software development might be more useful.