Best of Code Review 2013 — Gordian Knot Untied category

Please post your nominations for Best of Code Review 2013 — Gordian Knot Untied category: Most justified advice in an answer for taking a completely different approach from the code in the original question.

In your nomination post, be sure to include a link to the question, as well as a short explanation of why the advice is good. One nomination per post, please. Answers being nominated must date from 2013.

3 Answers

Speed up solution to Project Euler problem 75

In this answer I demonstrate the importance of choosing the right algorithm. The OP's program iterates over perimeters and then for each perimeter iterates over the Pythagorean triangles with that perimeter. By interchanging these loops (iterating outermost over the primitive Pythagorean triangles, and then for each primitive triangle generating all multiples of that triangle) the program can be sped up by more than 500 times.

A character array of arbitary length with 'R', 'B', 'W' is needed to be sorted in that order

The question states that a swap() method is available. The OP used it, as did three other answers. It turns out that the code is much easier to understand if you ignore swap() and just do a counting sort.

Rock-Paper-Scissors-Lizard-Spock Challenge

The question implements the Rock-Paper-Scissors-Lizard-Spock Challenge with an inheritance hierarchy which is cumbersome to maintain. Taking a different design approach greatly improves extensibility and decoupling of data and decisions.