Call Chain Kata

Last week, all of us in the dev team at Didit got to go to the SCNA conference in Chicago. I came away very inspired with an expanded view of Software Development.

Presentations from Bob Martin (Uncle Bob) and Zed Shaw (among others) focused on practicing coding like a musician practices their instrument and coding as often as possible (as opposed to getting mired in ideology and methodology).

Among the things I learned was the idea of coding Katas. These are small, but often tricky, problems designed to hone coding skill, more so than to find a solution to the problem. It’s all about practicing. Often times, the code will move from a standard approach to a more functional approach. Why? Functional programming can reduce or remove the reliance on state, often a source of nasty bugs. Here are some good Kata sites:

I’d like to present a Kata called “Call Chain” that is based on a real world problem of mine. I’ll post any tries at it that I do and feel free to post links to your own work.

The Problem

There are 6 people who call each other once a week to “check in” on how they are doing with various Katas they are working on. Each person calls one other person and receives a call from one other person. At the end of each week, a new call chain is setup. The goal is that each person will call and receive calls from each of the other people before the cycle repeats.

Here’s a sample week:

Alice calls Bob
Bob calls Charlie
Charlie calls Debbie
Debbie calls Eric
Eric calls Frank
Frank calls Gretchen
Gretchen calls Alice

The next week, no one should be calling anyone they called in the previous week, nor should they receive a call from anyone they received a call from in the previous week.

There are two other basic rules:

1) Who you call and who you receive a call from should not be the same person. For instance,

Alice calls Bob
Bob calls Alice

is not a valid pairing.

2) It’s probably obvious, but you can’t call yourself.

Bob calls Bob

is not valid.

Can you write a program that finds the optimal calling pattern? How many weeks of calling will there be before the pattern repeats?

More Fun

Can you solve for n number of people? Are there any differences when there is an even number of people compared to an odd number of people?

How about a new rule? Bob and Charlie are married and therefore should not call or receive calls from each other.

Adjust your code accordingly.

Have fun!



Leave a Reply