Prime Factors Kata in C#

Are you new to the concept of code katas? Read my previous blog post and watch me perform the String Calculator Kata.

In my never ending goal of self improvement in the techniques and tools I use I’ve been practicing a version of the Prime Factors Kata for a while.

The Prime Factors Kata, initially sparked by the infamous Uncle Bob Martin, is about finding an arbitrary number’s prime factors. In the cast I show how my TDD practice has evolved into a flavor of BDD, mainly to reduce duplication in the unit tests. I also show off the awesome power of my current toolset which includes the Visual Studio 2010 and the latest versions of ReSharper, TestDriven.NET, NUnit and NBehave.

Though my performance is not yet perfected I want to put it out there because I feel there are no C# version that can really match the Ruby version in elegance and wit. This is my attempt to show what you can do with the C# language when you know the frameworks really well.

Please leave comments and/or suggestions below or record your own kata session in response.


Prime Factors Kata in C# from Rickard Nilsson on Vimeo.


If you are new to the Prime Factors Kata, code katas in general, or TDD for that matter, you may find the steps I take unnecessary or weird. You may want to watch the annotated version in which Uncle Bob explains why each step is taken and why they are taken in that order.

Many have recorded there own versions of the Prime Factors Kata which all inspired me in the way I practice it. The cast that inspired me the most is

there are also a few other C# casts worth watching for comparison by:

Comments (5) -

  • Kay

    2/9/2014 12:34:21 AM | Reply

    Nice! What is the music?

    • Rickard

      2/9/2014 12:35:09 AM | Reply

      The music is a potpourri of the following classical pieces:
      Concerto For Violin And Oboe, Egyptian March, Morning Mood, Swan Lake, Symphony In C Major, and Waltz Opus 70 Number 1

  • Dhivya

    2/9/2014 12:35:54 AM | Reply

    Dear sir,

    I am Msc It student.
    I have to answer to the question What are factors of C#?
    Theoretically i need this answer.Can anybody know answer to this question pls mail to me.

  • staafl

    2/9/2014 12:36:36 AM | Reply

    neat Smile that if() at the end isn't needed though, is it?

    • Rickard

      2/9/2014 12:37:12 AM | Reply

      Well, with the optimization I did the if() is necessary. Without the optimization you can leave it out.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.