Kumite (ko͞omiˌtā) is the practice of taking techniques learned from Kata and applying them through the act of freestyle sparring.
You can create a new kumite by providing some initial code and optionally some test cases. From there other warriors can spar with you, by enhancing, refactoring and translating your code. There is no limit to how many warriors you can spar with.
A great use for kumite is to begin an idea for a kata as one. You can collaborate with other code warriors until you have it right, then you can convert it to a kata.
require 'mongoid'
File.open('mongoid.yml', 'w') do |file|
file.write <<-CONFIG
development:
sessions:
default:
database: mongoid
hosts:
- localhost:27017
CONFIG
end
fork do
exec 'mongod'
end
sleep 1 # need to find a better way to wait for mongo to startup
ENV['RACK_ENV'] = 'development'
Mongoid.load!('mongoid.yml')
class User
include Mongoid::Document
field :name
end
describe User do
it 'should save' do
Test.expect(User.new.save)
Test.assert_equals(User.count, 1)
end
end
Using Liebniz' formula... converges attrociously slowing...
(->> (iterate inc 0)
(map #(-> (Math/pow -1 %) (/ (inc (* 2 %)))))
(take 1200001)
(reduce +)
(* 4)
println)
(ns number-to-words (:require [clojure.string :refer [join]])) (def digit-to-word {1 "One" 2 "Two" 3 "Three" 4 "Four" 5 "Five" 6 "Six" 7 "Seven" 8 "Eight" 9 "Nine"}) (def tens-to-word { 20 "Twenty" 30 "Thirty" 40 "Fourty" 50 "Fifty" 60 "Sixty" 70 "Seventy" 80 "Eighty" 90 "Ninety"}) (def teen-to-word {10 "Ten" 11 "Eleven" 12 "Twelve" 13 "Thirteen" 14 "Fourteen" 15 "Fifteen" 16 "Sixteen" 17 "Seventeen" 18 "Eighteen" 19 "Nineteen"}) (defn divmod [n d] [(quot n d) (mod n d)]) (defn tens [n & {:keys [zero] :or {zero ""}}] (let [[tens ones] (divmod n 10) digit (digit-to-word ones)] (condp = tens 0 (or digit zero) 1 (teen-to-word n) (str (tens-to-word (* 10 tens)) (when digit (str "-" digit)))))) (defn order [d name f n] (let [[hs ts] (divmod n d)] (str "" (when (> hs 0) (str (f hs) " " name)) (when (> ts 0) (str (when (> hs 0) " ") (f ts)))))) (def hundreds (partial order 100 "Hundred" tens)) (def orders ["" " Thousand" " Million" " Billion" " Trillion"]) (defn addp [lst n o] (if (> n 0) (conj lst (str (hundreds n) (orders o))) lst)) (defn convert- [x] (join ", " (loop [i 0, n x, out '()] (let [[a b] (divmod n 1000)] (cond (>= a 1000) (recur (inc i) a (addp out b i)) (> a 0) (-> out (addp b i) (addp a (inc i))) :else (addp out b i) ))))) (defn convert [x] (case (compare x 0) -1 (str "Negative " (convert- (- (int x)))) 0 "Zero" 1 (convert- (int x)) nil))
1 1 (ns number-to-words
2 2 (:require [clojure.string :refer [join]]))
3 3 4 4 (def digit-to-word
5 − {1 "One"
6 − 2 "Two"
7 − 3 "Three"
8 − 4 "Four"
9 − 5 "Five"
10 − 6 "Six"
11 − 7 "Seven"
12 − 8 "Eight"
5 + {1 "One" 2 "Two" 3 "Three" 4 "Four"
6 + 5 "Five" 6 "Six" 7 "Seven" 8 "Eight"
13 13 9 "Nine"})
14 14 15 15 (def tens-to-word
16 16 {
17 − 20 "Twenty"
18 − 30 "Thirty"
19 − 40 "Fourty"
20 − 50 "Fifty"
21 − 60 "Sixty"
22 − 70 "Seventy"
23 − 80 "Eighty"
24 − 90 "Ninety"})
11 + 20 "Twenty" 30 "Thirty" 40 "Fourty"
12 + 50 "Fifty" 60 "Sixty" 70 "Seventy"
13 + 80 "Eighty" 90 "Ninety"})
… Expand 25 25 26 26 (def teen-to-word
27 − {10 "Ten"
28 − 11 "Eleven"
29 − 12 "Twelve"
30 − 13 "Thirteen"
31 − 14 "Fourteen"
32 − 15 "Fifteen"
33 − 16 "Sixteen"
34 − 17 "Seventeen"
35 − 18 "Eighteen"
16 + {10 "Ten" 11 "Eleven" 12 "Twelve"
17 + 13 "Thirteen" 14 "Fourteen" 15 "Fifteen"
18 + 16 "Sixteen" 17 "Seventeen" 18 "Eighteen"
36 36 19 "Nineteen"})
37 37 38 − (defn- small-number-to-words
39 − [x]
40 − (cond
41 − (<= x 9) (digit-to-word x)
42 − (< x 20) (teen-to-word x)
… Expand 43 − (< x 100)
44 − (let [ones-part (mod x 10)
45 − tens-part (- x ones-part)]
46 − (str (tens-to-word tens-part) "-"
47 − (digit-to-word ones-part)))
48 − (<= x 999)
49 − (let [small-part (mod x 100)
50 − hundreds-digit (-> x (- small-part) (/ 100))]
51 − (str (digit-to-word hundreds-digit) " Hundred " (small-number-to-words small-part)))))
52 − 53 − (defn- digit-shift
54 − [x shift]
55 − (-> x (- (mod x shift)) (/ shift) int))
56 − 57 − (defn convert
58 − [x]
59 − (loop [words [] x x]
60 − (cond
61 − 62 − (-> x (>= 1e6))
63 − (recur (conj words "One Million")
64 − (- x 1e6))
65 − 66 − (-> x (>= 1e3))
67 − (recur (conj words
68 − (str
69 − (-> x (digit-shift 1000) small-number-to-words)
70 − " Thousand"))
71 − (mod x 1000))
72 − 73 − (-> x (> 0))
74 − (recur (conj words (small-number-to-words x)) 0)
75 − 76 − :else (join ", " words))))
21 + (defn divmod [n d] [(quot n d) (mod n d)])
22 + … Expand 23 + (defn tens [n & {:keys [zero] :or {zero ""}}]
24 + (let [[tens ones] (divmod n 10)
25 + digit (digit-to-word ones)]
26 + (condp = tens
27 + 0 (or digit zero)
28 + 1 (teen-to-word n)
29 + (str (tens-to-word (* 10 tens)) (when digit (str "-" digit))))))
30 + 31 + (defn order [d name f n]
32 + (let [[hs ts] (divmod n d)]
33 + (str ""
34 + (when (> hs 0) (str (f hs) " " name))
35 + (when (> ts 0) (str (when (> hs 0) " ") (f ts))))))
36 + 37 + (def hundreds (partial order 100 "Hundred" tens))
38 + 39 + (def orders ["" " Thousand" " Million" " Billion" " Trillion"])
40 + 41 + (defn addp [lst n o]
42 + (if (> n 0) (conj lst (str (hundreds n) (orders o))) lst))
… Expand 43 + 44 + (defn convert- [x]
45 + (join ", "
46 + (loop [i 0, n x, out '()]
47 + (let [[a b] (divmod n 1000)]
48 + (cond
49 + (>= a 1000) (recur (inc i) a (addp out b i))
50 + (> a 0) (-> out (addp b i) (addp a (inc i)))
51 + :else (addp out b i)
52 + )))))
53 + 54 + (defn convert [x]
55 + (case (compare x 0)
56 + -1 (str "Negative " (convert- (- (int x))))
57 + 0 "Zero"
58 + 1 (convert- (int x))
59 + nil))
(ns number-to-word-test (:require [clojure.test :refer :all] [number-to-words])) (deftest conversion-test (is (= "Zero" (number-to-words/convert 0))) (is (= "One" (number-to-words/convert 1))) (is (= "Seven" (number-to-words/convert 7))) (is (= "Eleven" (number-to-words/convert 11))) (is (= "Ninety" (number-to-words/convert 90))) (is (= "Twenty-Six" (number-to-words/convert 26))) (is (= "Three Hundred Eleven" (number-to-words/convert 311))) (is (= "Two Hundred Two" (number-to-words/convert 202))) (is (= "Seven Hundred" (number-to-words/convert 700))) (is (= "Five Hundred Ninety-Nine" (number-to-words/convert 599))) (is (= "One Million" (number-to-words/convert 1e6))) (is (= "Nine Hundred Ninety-Nine Thousand" (number-to-words/convert 999e3)) (is (= "Six Hundred Twelve Thousand, Three Hundred Twenty-Three" (number-to-words/convert 612323)))))
1 1 (ns number-to-word-test
2 2 (:require [clojure.test :refer :all]
3 3 [number-to-words]))
4 4 5 5 (deftest conversion-test
6 + (is (= "Zero" (number-to-words/convert 0)))
7 + (is (= "One" (number-to-words/convert 1)))
8 + (is (= "Seven" (number-to-words/convert 7)))
9 + (is (= "Eleven" (number-to-words/convert 11)))
10 + (is (= "Ninety" (number-to-words/convert 90)))
11 + (is (= "Twenty-Six" (number-to-words/convert 26)))
12 + (is (= "Three Hundred Eleven" (number-to-words/convert 311)))
13 + (is (= "Two Hundred Two" (number-to-words/convert 202)))
14 + (is (= "Seven Hundred" (number-to-words/convert 700)))
15 + (is (= "Five Hundred Ninety-Nine" (number-to-words/convert 599)))
6 6 (is (= "One Million" (number-to-words/convert 1e6)))
7 7 (is (= "Nine Hundred Ninety-Nine Thousand" (number-to-words/convert 999e3))
8 8 (is (= "Six Hundred Twelve Thousand, Three Hundred Twenty-Three" (number-to-words/convert 612323)))))
int main()
{
printf("%d\n", test());
}
int test()
{
__asm__("movl $1337, %eax");
}
A basic example of how to run a Redis in ruby on CW.
fork do
exec "redis-server"
end
require 'redis'
r = Redis.new
r.set('a', 'b')
Test.assert_equals(r.get('a'), 'b')
When you have a thread ouputting to stdout, and you want to catch its output in a test case...
(defmacro with-out-str-not-thread-safe
"A version of clojure.core/with-out-str that is not thread-safe"
[& body]
`(let [s# (StringWriter.)]
(with-redefs [*out* s#]
~@body
(str s#))))
class Array # Opens up the Array class for method creation def flip self.reverse.map{|e| e.is_a?(Array) ? e.flip : e} end end
1 1 class Array # Opens up the Array class for method creation
2 2 def flip
3 − result = []
4 − me = self.reverse # Don't fret, I'll sort the Arrays out!
5 − 6 − me.each do |x|
7 − 8 − if x.class == Array then result << x.flip # Here's the recursion.
9 − else result << x
10 − end
11 − 12 − end
13 − 14 − return result
3 + self.reverse.map{|e| e.is_a?(Array) ? e.flip : e}
15 15 end
16 16 end
class Solution {
public static void main(String[] args) {
System.out.println("Hello darkness, my old friend...");
}
}
A Tail recursive factorial function
Factorial = fun(N) when N > 0 -> Tail = fun (Y, Acc, 0) -> Acc; (Y, Acc, N) -> Y(Y, Acc * N, N - 1) end, Tail(Tail, 1, N) end, io:format("~s~n", [Factorial(5)]),
1 − Factorial = fun (Y, 0) -> 1;
2 − (Y, N) -> N * Y(Y, N - 1)
3 − end,
1 + Factorial = fun(N) when N > 0 ->
4 4 5 − io:format("~p~n", [Factorial(Factorial, 5)]),
3 + Tail = fun (Y, Acc, 0) -> Acc;
4 + (Y, Acc, N) -> Y(Y, Acc * N, N - 1)
5 + end,
6 + 7 + Tail(Tail, 1, N)
8 + end,
6 6 7 − init:stop().
10 + io:format("~s~n", [Factorial(5)]),