Can you solve this code kata?

BTI360 Blog / July 14, 2014 in 

Last week at BTI360 we hosted a Code Kata Night. We spent time sharpening our coding skills and honing our craft.

And now we’d like to share the kata with you!

Try it out! Solve it! And then scrap your code and take a different approach.

Code an algorithm for the following sequence:

1
11
21
1211
111221
. . .

Can you determine the next value? Here’s the same sequence with a new starting number:

4
14
1114
3114
132114
. . .

Got it yet? Not obvious?

The code kata is the Look-and-Say sequence. Typically, when we see a numeric sequence and are asked to come up with the next number in the sequence, that number is based on some arithmetic operation. The look-and-say sequence, which at first glance appears to be another such sequence where an algorithm is required to compute each item, is actually a visual sequence where each number following the first number (typically “1”) is simply a visual description of the number before it.

What does “1” look like? There is one 1 (11). What does 11 look like? Two 1s (21). Next would be 1211 (1 2 and 1 1).

The code kata consisted of 3 rounds:

  1. Code a simple function that would take as its input a number (as a numeric string parameter) in the sequence, and then return the next number (also a string) in the sequence.
  2. The next activity was to write another function with the same input and output arguments, but using a regular expression instead of iterating over each character.
  3. Choose a variation like reverse the sequence and stopping at the appropriate times. Or solve the kata without any looping structures (i.e. use recursion).

We learned! We got better! We had a lot of fun! And now it’s your turn!

Try out the kata. We’ll post some of our team’s solutions later this week so you can see how your solutions stack up.

Previous

Code Kata Challenge – And the Winner Is…

Next

How would you code the Look-and-Say sequence?

Close Form

Enjoy our Blog?

Then stay up-to-date with our latest posts delivered right to your inbox.

  • This field is for validation purposes and should be left unchanged.

Or catch us on social media

Stay in Touch

Whether we’re honing our craft, hanging out with our team, or volunteering in the community, we invite you to keep tabs on us.

  • This field is for validation purposes and should be left unchanged.