You have to manage product codes for a specific inhouse portfolio. All product codes in your company follow a certain convention. A product code is separated into two parts – a single character department source qualifier and a unique product number.

An Enigma for products

Example Product Codes: A1, B52, D2, X404

The "department source qualifier" (aka DSQ)
|
v
B52
 ^^
  |
  The product number (aka PN)

Moreover, you have two separate lists of product codes at hand. The first list is from your CEO, while the second list origins from internal controlling department. Obviously, both lists are different. It’s not only that one list contains product codes the other does not have, but as well that both lists seem to have different product numbering schemes.

Make your CEO happy

You have been assigned by your CEO to complete the following task: Pick all “akin” products by examining their DSQ. If both lists contain product codes of same DSQ, remove them from original list and copy them over to a new “Akin”-List. Leave the remaining product codes as is.

The following two lists:

  ceoList = [A1,B1,A2,A3,C1,D1,E1,E2]
  controlList = [F1,D2,B2,B3,A4]

Results in following “Akin List” with modified CEO and control lists:

  akinList = [A1,B2,A2,A3,B3,A4,D1,D2,B1]
  ceoList = [C1,E1,E2]
  controlList = [F1]

(Note: The order is not relevant)

Be smart

Let’s put it straight: Write a program that takes two lists (ceoList and controlList) containing an arbitrary set of product codes in the above described format. The program produces three lists. The first list is the akinList, that is, the list of all akin products taken from the input lists. The remaining two lists are the reduced ceoList and controlList, respectively.

About

The kata stems from a real life scenario. Actually, I did not invent the kata, all credits go to its original inventor, Dr.M. What I did is just to take the essence of the problem and rephrase it a little bit with a story. That’s it.

The objective of this kata is to sharpen design skills for trivial algorithms. Dr.M originally posted the problem alongside with a requirement of maximum time complexity O(n^2). A secondary requirement for the solution algorithm is terseness and expressiveness. The more elegant your algorithm is (with respect to the time complexity), the “better”. Although it should be paid attention to both non-functional requirements, they’re just a “nice to have”.

“Pick Akin” is a great little problem to chew on. It teaches you lightweight algorithm design while exposing you to the world of list processing and mingling. It is indeed a good code kata to practice your TDD / BDD skills.

This code kata is dedicated to its inventor, Dr.M.

@ilkerde

Comments
This article has 2 comments:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Hi Ilker, a dirty...
    by Mike Bild
    on May 2nd 2011

    Hi Ilker,

    a dirty LINQ based solution – http://bit.ly/mRx3vp. No specs are included. Sorry, it’s a complex test szenario for me. How would you proceeding test-driven or specs?

  • What can I...
    by Harald M.
    on April 24th 2011

    What can I say that I think? Well, I try to say it at http://swemusings.blogspot.com/2011/04/pickakin-kata-part-one.html :-)

    Regards, and of course many thanks for taking up that idea!

    Harald M.


(c) 2000-2012 ilker.de - Creative Computing.

For any case of inquiry regarding this document, you can always contact the website owner.