r/programming • • May 09 '15

"Real programmers can do these problems easily"; author posts invalid solution to #4

https://blog.svpino.com/2015/05/08/solution-to-problem-4
3.1k Upvotes

1.3k comments sorted by

View all comments

Show parent comments

38

u/jrmrjnck May 09 '15

Yeah, the point of the question was basically to calculate that table. I don't know what he's going on about.

4

u/ILikeBumblebees May 09 '15 edited May 09 '15

Yeah, the point of the question was basically to calculate that table.

Well, that's where the "brute force" comes into play, and implementing a brute force algorithm to solve this problem is itself very trivial: you just enumerate every permutation of operators, then evaluate each permutation, test to see if the returned value is 100, and store the resulting boolean value.

The point is that it's more efficient to do this once and store the results as data than to actually compute all of the results at runtime, even with a more clever recursive algorithm.

0

u/[deleted] May 09 '15

[deleted]

0

u/ILikeBumblebees May 09 '15

All you'd achieve with that solution is make the impression that you're either showing off or have no idea what "premature optimization" means.

I don't think it makes sense to regard "let's brute-force this, and then find an efficient way to store the results so we don't have to do it over again" as either premature optimization or showing off. Quite the opposite: coming up with clever tricks to do it in fewer lines of more complicated code seems to better fit the bill on both counts.

→ More replies (5)