Start a new Kumite
AllAgda (Beta)BF (Beta)CCFML (Beta)ClojureCOBOL (Beta)CoffeeScriptCommonLisp (Beta)CoqC++CrystalC#D (Beta)DartElixirElm (Beta)Erlang (Beta)Factor (Beta)Forth (Beta)Fortran (Beta)F#GoGroovyHaskellHaxe (Beta)Idris (Beta)JavaJavaScriptJulia (Beta)Kotlinλ Calculus (Beta)LeanLuaNASMNim (Beta)Objective-C (Beta)OCaml (Beta)Pascal (Beta)Perl (Beta)PHPPowerShell (Beta)Prolog (Beta)PureScript (Beta)PythonR (Beta)RacketRaku (Beta)Reason (Beta)RISC-V (Beta)RubyRustScalaShellSolidity (Beta)SQLSwiftTypeScriptVB (Beta)
Show only mine

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.

Ad
Ad

The Itertools module offers a the generator permutations that gives a permutation as a tuple, each time. Nevertheless the result will not be printed because some outputs are huge.

from itertools import *

def permut(arr):
    resL = []
    for perm in permutations(arr):
        resL.append(list(perm))
    return resL
Algorithms
Logic
(ns quicksort.core)

(defn quick-sort [nums]
  (if (< (count nums) 2) nums
    (concat
      (quick-sort (filter #(< % (first nums)) nums))
      (filter #(= % (first nums)) nums)
      (quick-sort (filter #(> % (first nums)) nums)))))

Shows how to use bash kta and how to create simple tests

echo Hello Bash!

When we want to generate primes we may have problems of memory if we use cumulative data structures. The following code generates each prime lazely using a generator instead of a function. To generate the prime numbers we use a primality test as a helper function

function isPrime(n) {
    if (n%1 || n<2) return false;
    var upper = Math.round(Math.pow(n, 1/2.0));
    for (var i = 2;i <= upper; i++) if (n % i == 0) return false;
    return true;
}

function *primeGener() {
    var i = 0;
    while(true) {
        if(isPrime(i)) yield i;
        i += 1;
    }
}

function countPrimes(limit) {
    var count = 0, call = primeGener();
    while(true) {
        var prime = call.next().value;
        if (prime > limit) break;
        count++
    }
    return count
}

This kumite reverses a string in bash.

#!/bin/bash

echo $1 | rev

Here we show a way to produce prime numbers using a python generator instead a function.
The algorithm of eratosthenes is one of the most optimized in Python. It was taken from a cookbook recipies. (credits to the authors)

import itertools
from itertools import *
def eratosthenes():
    #From Coobook recipies
    #Credits to: Credit: David Eppstein, Tim Peters, Alex Martelli,
    #Wim Stolker, Kazuo Moriwaka, Hallvard Furuseth, Pierre Denis, 
    #Tobias Klausmann, David Lees, Raymond Hettinger
    D = {  }
    yield 2
    for q in itertools.islice(itertools.count(3), 0, None, 2):
        p = D.pop(q, None)
        if p is None:
            D[q*q] = q
            yield q
        else:
            x = p + q
            while x in D or not (x&1):
                x += p
            D[x] = p
            
def count_primes(limit):
    count = 0
    for prime in eratosthenes():
        if prime > limit: return count
        count += 1
def permut(arr)
    arr.permutation.to_a
end
UnnamedFailed Tests

Shell test

echo "$1"
printf test
echo $1