Skip to content

Instantly share code, notes, and snippets.

@ReitenSchnell
Created August 29, 2012 08:04
Show Gist options
  • Save ReitenSchnell/3508302 to your computer and use it in GitHub Desktop.
Save ReitenSchnell/3508302 to your computer and use it in GitHub Desktop.
Prime factors kata
Although quite short, this kata is fascinating in the way it shows how ‘if’ statements become ‘while’ statements as the number of test cases increase. It’s also a wonderful example of how algorithms sometimes become simpler as they become more general.
1. Write a class named “PrimeFactors” that has one method: generate. The generate method takes an integer argument and returns a List<Integer>. That list contains the prime factors of argument in numerical sequence.
2. Write test and code for argument = 1. Result should be empty list.
3. Write test and code for argument = 2. Result should be [2].
4. Write test and code for argument = 3. Result should be [3].
5. Write test and code for argument = 4. Result should be [2,2].
6. Write test and code for argument = 6. Result should be [2,3].
7. Write test and code for argument = 8. Result should be [2,2,2].
8. Write test and code for argument = 9. Result should be [3,3].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment