Created
April 27, 2012 22:40
-
-
Save awostenberg/2514008 to your computer and use it in GitHub Desktop.
prime factors kata clojure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;;today's timed kata from https://github.com/hoodja/practice-to-learn | |
| ;;down to 15 minutes today from 30 minutes previously | |
| (ns com.pillartechnology.practice | |
| (:use clojure.test midje.sweet)) | |
| (defn factors | |
| ([n] (factors n 2)) | |
| ([n c] | |
| (if (= n 1) | |
| [] | |
| (if (zero? (mod n c)) | |
| (cons c (factors (/ n c) c )) | |
| (factors n (inc c)) )))) | |
| (deftest testOne | |
| (fact (factors 1) => [])) | |
| (deftest testTwo | |
| (fact (factors 2) => [2])) | |
| (deftest testFour | |
| (fact (factors 4) => [2 2])) | |
| (deftest testSix | |
| (fact (factors 6) => [2 3])) | |
| (deftest testNine | |
| (fact (factors 9) => [3 3])) | |
| (deftest testThirty | |
| (fact (factors 30) => [2 3 5])) | |
| (run-tests 'com.pillartechnology.practice) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a finished Kata presented at Mile High Agile 2012 by James Hood (see https://github.com/hoodja/practice-to-learn). I took Jame's suggestion and use it for a daily warmup. I also run the Pomodoro timer http://www.pomodorotechnique.com/; my last time was under 15 minutes & finished minutes before a job interview. James is right: it's a way to relax!