Coding Kata – January 25 2010
1.25.2010 | Kata
Goal: Design a data structure and controller to model a Connect Four game.
Your controller must have two functions, putPiece and checkForWin (using any parameters you choose).
Constraints: Your checkForWin method should be relatively efficient (i.e. it can’t have O(n2) efficiency). Think you can do it in O(n)? How about O(1)?
Hmmm of the day: The most efficient way to put a piece may seem a little ‘backwards’ at first.




1.25.2010
Did you know? With perfect play, the first player can force a win by starting in the middle column. By starting in the two adjacent columns, the first player allows the second player to reach a draw; by starting with the four outer columns, the first player allows the second player to force a win.
1.25.2010
@Shaun Hm, that’s an interesting idea! I’ve heard about this before, but I’ve never played it out. I’ll think about it though! Have you ever tried it before? And secondly, do you have any ideas you’d like to try for this coding puzzle?
1.25.2010
I feel like I’ve done this problem somewhere before during some development that was rapid.
Great idea picking up the coding kata, though. I may try my hand at a few (though my own projects tend to take up most of my free time as it is).
1.26.2010
I’ve received some special requests to not put up the answer just yet, so I’ll put it up tomorrow with the solution to the array rotation, if you’re really keen though, feel free to email me and I’ll send you my solution!
What’s really cool to note here is that your solution could blow mine or anyone else’s out of the water. I create these questions before solving them, so my thoughts are by no means the absolute correct answer. It’s designed to be more of an open forum in theory.
There’s also plenty of equivalent solutions too, so don’t be bashful!