Kata

Kata


Coding Kata – February 1st 2010 – Flippin’ Lists

2.01.2010 | 3 Comments

Goal: Flip tuples in a doubly linked list.
Example: Given A <-> B <-> C <-> D, have an algorithm produce B <-> A <-> D <-> C.

Constraints: All manipulations must be made to the original linked list, and minimize use of external data structures as much as possible.

Hmmm of the day: The ideal solution is fairly brief and elegant, so don’t try to over-think it unless you need to!


Coding Kata – January 29 2010 – Playing Vegas

1.29.2010 | 4 Comments

Goal: Design and implement an algorithm to detect certain hands in a game of Poker. You are given your parameters as 5 ints [0-13] representing each value of the card. The hands to check are:

  • Four of a kind (ex: 5,4,5,5,5)
  • Full house (ex: 5,4,4,5,5)
  • Three of a kind (ex: 5,4,5,5,1)
  • Two pair (ex: 8,4,4,5,5)
  • Pair (ex: 7,1,2,5,5)
  • High card (ex: 1,2,3,4,5)

Constraints:

  • Return the String value or enum code (to your specification) representing each case

Hmmm of the day: Are there any poker hands which could fall into more than one category?


Coding Kata – January 28 2010 – Crazy List Copying

1.28.2010 | 0 Comments

Goal: Create a duplicate copy of a linked list given the following facts about the linked list:

  • Each node in the list has a pointer to the next element in the list, or null if no element is present
  • Each node in the list has a data pointer which points to any arbitrary node in the list

Constraints:

  • You are allowed to modify the list, so long as it is returned to its original state

Example:

Hmmm of the day: Can this be solved using pointer arithmetic, and if so, is it the most efficient solution?


Coding Kata – January 27 2010 – The Ski Lift

1.27.2010 | 0 Comments

Goal: Create an algorithm to determine how close you are to the summit of a mountain (percentage) whilst on a chairlift. You know the following information:

  • What chair you are on
  • The chair coming in the opposite direction visible to your left at the current time

At what point do you have an accurate estimate of your progress? When you are at that point, what is your percentage progress to the top?

Constraints: You are not given the number of chairs on the chairlift.


Coding Kata – January 26 2010

1.26.2010 | 0 Comments

Goal: Create code to rotate an N by N array 90 degrees clockwise.

Constraints: All manipulations must be made to the original array, but a single staging variable can be used.

Hmmm of the day: Can this be done for N by M arrays as well? If so, how? If not, why not?


Coding Kata – January 25 2010

1.25.2010 | 4 Comments

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.


Coding Kata

1.25.2010 | 0 Comments

Ever write code that looks like this?

thatll_work

If you’re saying no, then you’re either a legend or you might have some delusions of grandeur – but in any case a little practice never hurt anybody. I’ve decided to keep my skills fresh, I’m going to try and create (and tackle) a new problem every day, and I’d like to share them with the rest of the world so that you might benefit as well.

This concept is by no means new, and I encourage you to check out Dave Thomas’ Coding Kata, which is the earliest example of Coding Kata I can find. I really like the concept, but unfortunately the site is no longer maintained, so I’d like to pick up the torch and carry on from where Dave left off.

Some of them you may have come across some of before, but I’ll try to keep them as fresh as possible. I’ll also post the answer in the comments the next day for those who are interested. Karma points to whoever gets it first before that though :)