Nominating this answer from Gareth Reesanswer from Gareth Rees to the question Google Foobar Challenge: Lucky TriplesGoogle Foobar Challenge: Lucky Triples for the lengthy details and teaching nature of an answer that boils down to "your code doesn't work as expected, try this instead".
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/