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
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.
Solution
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.
読んでくれてありがとう。