Begin a new Kumite
Search
About
  • Filter by Language:
  • 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...

Code
Diff
  • #!/bin/bash
    printf "Hello %s!\n" "Bash"
  • 1
    #!/bin/bash          
    
    2
    echo Hello Bash!
    
    1+
    #!/bin/bash
    
    2+
    printf "Hello %s!\n" "Bash"
    

Even more golfing

Code
Diff
  • (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))))
  • 11
    (ns bubble
    
    22
      (:refer-clojure :exclude [sort]))
    
    33
    4
    (defn bubble [tanks]
    
    5
      (if (or (nil? tanks) (nil? (next tanks)))
    
    6
        [tanks false]
    
    7
        (let [[truck & [jeep & _ :as convoy]] tanks]
    
    8
          (if (<= truck jeep)
    
    9
            (let [debrief (bubble convoy)] (cons (cons truck (first debrief)) (next debrief)))
    
    10
            (cons (cons jeep (first (bubble (cons truck (next convoy))))) '(true))))))
    
    4+
    (defn bubble [[truck & [jeep & bigdogs :as convoy] :as tanks]]
    
    5+
      (cond
    
    6+
       (some nil? [truck convoy]) [tanks true]
    
    7+
       (<= truck jeep) (update-in (bubble convoy) [0] conj truck)
    
    8+
       :else [(cons jeep (first (bubble (cons truck bigdogs)))) false]))
    
    1111
    1212
    (defn sort [l]
    
    13
      (let [bubbly (bubble l)]
    
    14
        (if (second bubbly)
    
    15
          (recur (first bubbly))
    
    16
          (first bubbly))))
    
    11+
      (let [[value done?] (bubble l)]
    
    12+
        (if done?
    
    13+
          value
    
    14+
          (recur value))))
    

I use this whenever I have to add another directory to my PATH environment variable in my .bashrc. This way I don't have duplicates.

I wrote this years ago and it's hacky and kind of dumb... I'm sure it can be improved.

add_PATH() {
        oIFS=$IFS
        IFS=':'
        t=(${PATH})
        unset IFS
        t=("$1" ${t[@]%%"$1"})
        # output the new array
        IFS=':'
        echo -n "${t[*]}"
        unset t
        IFS=$oIFS
}

echo "Original Path: $PATH"
export PATH=$(add_PATH /usr/local/bin)
echo "New Path: $PATH"

"Hello Python!" script.

print "Hello Python!"
Arrays
Blocks
Object-oriented Programming
Functions
Control Flow
Basic Language Features
Fundamentals

A refactor of jhoffner's code. I edited the Array#sum code, so take a look at the changes.

Code
Diff
  • 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
  • 11
    class Array
    
    22
      def sum(&block)
    
    3
        inject(0) do |result, item|
    
    4
          item = block_given? ? yield(item) : item
    
    5
          result + (item || 0)
    
    6
        end
    
    3+
        block = Proc.new {|n| n} unless block_given?
    
    4+
        inject(0) {|result, item| result + block.call(item) rescue result}
    
    77
      end
    
    88
      
    
    99
      def mean(&block)
    
    1010
        sum(&block).to_f / size
    
    1111
      end
    
    1212
    end
    
Mathematics
Algorithms
Numbers
Code
Diff
  • cats :: [Integer]
    cats = 1 : [ c_n * 2 * (2 * n + 1) `div` (2 + n) |
                 (c_n, n) <- zip cats [0..] ]
    
    main = putStrLn $ show $ take 10 cats
  • 11
    cats :: [Integer]
    
    2
    cats = 1 : do
    
    3
      (c_n, n) <- zip cats [0..]
    
    4
      return $ c_n * 2 * (2 * n + 1) `div` (2 + n)
    
    5
      
    
    2+
    cats = 1 : [ c_n * 2 * (2 * n + 1) `div` (2 + n) |
    
    3+
                 (c_n, n) <- zip cats [0..] ]
    
    4+
    66
    main = putStrLn $ show $ take 10 cats