Monday, 10 November 2014

Something after the weekend...

G'day:
This is just a follow-up to my Friday article: "Something for the weekend? A wee code puzzle (in CFML, PHP, anything really...)". There's a bunch of good entries: cheers for that. There's CFML, PHP, Go, Python and Clojure examples there. However I'll still looking for more though: it's not too late to give it a bash. I have not looked at any of them (beyond superficially) yet, as I didn't want other people's work influencing my own.



I've written my code (PHP and CFML versions): it's on Github. It's disarrayed at present as I was doing it on a 1.5h flight to Ireland on Friday evening, and did not have PHPUnit installed so was naughty and eschewed the TDD approach. One thing I noticed when doing so is that I didn't pick up a lot of bugs in my logic that I would have had I used TDD.

As a penance I am back-filling the TDD approach, redeveloping the code using TDD following the same route I followed whilst ironing the logic errors out in getSubseries1() (which is awful code: don't look at that one), and following through the refactoring through to getSubseries4(). It'll take me a day or so to find time to finish this exercise.

Those are the PHP versions: the CFML versions were based on getSubseries4(), as that's the logic/approach that sits best with me (except a coupla things which I'll talk about later). There's no TDD for that code. Although this is probably a poor approach: I should have ported the tests first, so I knew I had migrated my logic properly. Hmmm...

I'm part-way through a Ruby solution too, but that will simply be following the same logic, so not very interesting, other than how different languages to the same thing (I can't see the Ruby solution being that much different from the CFML one).

Cheers for everyone who's offered some code so far: please do keep posting more responses if you can be arsed.

Righto... need to find out how to do a .reduce() in Ruby...

--
Adam