4 ms·
I was asked to solve this puzzle once during a project management interview. The solution here says "work backwards," but I found that "work recursively" was a
by andyraskin 11y ago
I was asked to solve this puzzle once during a project management interview. The solution here says "work backwards," but I found that "work recursively" was a more helpful (and instructive) way to think about it.
- kbutler 11y agoApplying the maximization of benefit logic, "work backwards" is very meaningful to a very large population of readers, "work recursively" is somewhat more meaningful to a very small population.
- seivan 11y agoThey could have explained it differently instead of going backwards. I tried to explain the backwards part to my mum and she didn't quite grok it. Then I explained it from perspective of A, B, C and so on. When A is in charge this affects.... When B is in charge this affects... Maybe that's recursively? solve(pirates) {..... solve(mutatedPirates) }
- tamana 11y agoThe are very similar. Recursion is expressing a problem in terms of a smaller case of the same problem. Working backwards/induction is building up from a base case.
- andyraskin 11y agoRecursion is exactly the same (as induction) because it also requires specifying what to do in a base case. I guess I think recursion is a more instructive term than "working backwards" because it speaks to a rigorous programmatic approach.
- hisham_hm 11y agoWikipedia is not written for programmers only.
- coldcode 11y agoI had to do this in a programming interview. Thankfully people don't do this type of question much any more.