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.
Bash is pretty silly...
Even more golfing
(ns bubble (:refer-clojure :exclude [sort])) (defn bubble [[truck & [jeep & bigdogs :as convoy] :as tanks]] (cond (some nil? [truck convoy]) [tanks true] (<= truck jeep) (update-in (bubble convoy) [0] conj truck) :else [(cons jeep (first (bubble (cons truck bigdogs)))) false])) (defn sort [l] (let [[value done?] (bubble l)] (if done? value (recur value))))
- (ns bubble
- (:refer-clojure :exclude [sort]))
(defn bubble [tanks](if (or (nil? tanks) (nil? (next tanks)))[tanks false](let [[truck & [jeep & _ :as convoy]] tanks](if (<= truck jeep)(let [debrief (bubble convoy)] (cons (cons truck (first debrief)) (next debrief)))(cons (cons jeep (first (bubble (cons truck (next convoy))))) '(true))))))- (defn bubble [[truck & [jeep & bigdogs :as convoy] :as tanks]]
- (cond
- (some nil? [truck convoy]) [tanks true]
- (<= truck jeep) (update-in (bubble convoy) [0] conj truck)
- :else [(cons jeep (first (bubble (cons truck bigdogs)))) false]))
- (defn sort [l]
(let [bubbly (bubble l)](if (second bubbly)(recur (first bubbly))(first bubbly))))- (let [[value done?] (bubble l)]
- (if done?
- value
- (recur value))))
A refactor of jhoffner's code. I edited the Array#sum code, so take a look at the changes.
class Array def sum(&block) block = Proc.new {|n| n} unless block_given? inject(0) {|result, item| result + block.call(item) rescue result} end def mean(&block) sum(&block).to_f / size end end
- class Array
- def sum(&block)
inject(0) do |result, item|item = block_given? ? yield(item) : itemresult + (item || 0)end- block = Proc.new {|n| n} unless block_given?
- inject(0) {|result, item| result + block.call(item) rescue result}
- end
- def mean(&block)
- sum(&block).to_f / size
- end
- end