Skip to content

Instantly share code, notes, and snippets.

@awostenberg
Created April 27, 2012 22:40
Show Gist options
  • Select an option

  • Save awostenberg/2514008 to your computer and use it in GitHub Desktop.

Select an option

Save awostenberg/2514008 to your computer and use it in GitHub Desktop.
prime factors kata clojure
;;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)
@awostenberg

Copy link
Copy Markdown
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment