Code Katas in Swift (#1 Roman Numerals)

Code Kata

型 かた:kata (set sequence of positions and movements in martial arts); style (in kabuki, noh, etc.); form

How do you get good at something? I mean really good. How does a musician, a surgeon, a basketball player get good?

I’ve never “practiced” programming. I always simply had and idea and I hacked away until it worked. Over time my hacks became less chaotic and more pattern-like. Now I realized that coding is the same as basketball. If you want to get into the NBA, you need to do what Kobe Bryant did. Study and practice.

In Japan, they have a word for deliberate repeated practice called kata. These are code katas. If you want to improve your programming skills as well, try them out too.

Kata#1: The Roman Numerals Problem

Photo by Concha Mayo

This kata is to write a roman numbers encoder. With an input of a number, output its equivalent in roman numbers.

E.G ~ 1954 -> MCMLIV 600-> DC 3422 MMMCDXXII 77 -> LXXVII

Interestingly the maximum number you can count to is 3999: MMMCMXCIX because there is no roman numeral past 1000: M.

All of the Roman Numerals


I’m going to post the first thing I came up with instead of the perfect answer to document improvement over time. If I don’t write better code after doing a bunch of these then I’m doing something wrong.

I solved this one while taking a walk (a very long walk) so these are really fun problems you can do in the shower or whenever. Think you can handle it? Try it out and let me know how you did on twitter.




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Hey, I’m Jason Cheladyn. Going back to the coding world after 6 years of teaching English in Japan.