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
Fundamentals
Code
Diff
  • package main
    
    import (
    	"fmt"
    )
    
    func main() {
    	fmt.Println("Hello Golang")
    }
    • #include <iostream>
    • #include <string>
    • package main
    • int helloCplusplus(){
    • std::string str = "Hello, C++!";
    • std::cout << str << '\n';
    • return 0;
    • import (
    • "fmt"
    • )
    • func main() {
    • fmt.Println("Hello Golang")
    • }
Code
Diff
  • #include <string>
    #include <stdio.h>
    
    int Main()
    {
      int arg1, arg2, add, sub, mul, quo, rem ;
    
        printf( "Enter two integer numbers : " );
        scanf( "%d%d", &arg1, &arg2 ); //no scanf provided hope to get memory garbage as number
    
        /* Perform Addition, Subtraction, Multiplication & Division */
        __asm__ ( "addl %%ebx, %%eax;" : "=a" (add) : "a" (arg1) , "b" (arg2) );
        __asm__ ( "subl %%ebx, %%eax;" : "=a" (sub) : "a" (arg1) , "b" (arg2) );
        __asm__ ( "imull %%ebx, %%eax;" : "=a" (mul) : "a" (arg1) , "b" (arg2) );
    
        __asm__ ( "movl $0x0, %%edx;"
                  "movl %2, %%eax;"
                  "movl %3, %%ebx;"
                   "idivl %%ebx;" : "=a" (quo), "=d" (rem) : "g" (arg1), "g" (arg2) );
    
        printf( "%d + %d = %d\n", arg1, arg2, add );
        printf( "%d - %d = %d\n", arg1, arg2, sub );
        printf( "%d * %d = %d\n", arg1, arg2, mul );
        printf( "%d / %d = %d\n", arg1, arg2, quo );
        printf( "%d %% %d = %d\n", arg1, arg2, rem );
    
        return 0 ;
    }
    • int main()
    • {
    • printf("%d\n", test());
    • }
    • #include <string>
    • #include <stdio.h>
    • int test()
    • int Main()
    • {
    • __asm__("movl $1337, %eax");
    • int arg1, arg2, add, sub, mul, quo, rem ;
    • printf( "Enter two integer numbers : " );
    • scanf( "%d%d", &arg1, &arg2 ); //no scanf provided hope to get memory garbage as number
    • /* Perform Addition, Subtraction, Multiplication & Division */
    • __asm__ ( "addl %%ebx, %%eax;" : "=a" (add) : "a" (arg1) , "b" (arg2) );
    • __asm__ ( "subl %%ebx, %%eax;" : "=a" (sub) : "a" (arg1) , "b" (arg2) );
    • __asm__ ( "imull %%ebx, %%eax;" : "=a" (mul) : "a" (arg1) , "b" (arg2) );
    • __asm__ ( "movl $0x0, %%edx;"
    • "movl %2, %%eax;"
    • "movl %3, %%ebx;"
    • "idivl %%ebx;" : "=a" (quo), "=d" (rem) : "g" (arg1), "g" (arg2) );
    • printf( "%d + %d = %d\n", arg1, arg2, add );
    • printf( "%d - %d = %d\n", arg1, arg2, sub );
    • printf( "%d * %d = %d\n", arg1, arg2, mul );
    • printf( "%d / %d = %d\n", arg1, arg2, quo );
    • printf( "%d %% %d = %d\n", arg1, arg2, rem );
    • return 0 ;
    • }
Code
Diff
  • (ns basics.core)
    
    (defn add [a b] (+ a b))
    (defn square [x] (* x x))
     
    (def result (-> (add 1 2) (add 3) (add 4) (square)))
    
    (println result)
    
    ;; It is better (without def), but it is more difficult to test:
    ; (let [result (-> (add 1 2)
    ;                  (add 3)
    ;                  (add 4)
    ;                  (square))]
    ;  (print result))
    
    ;; Shorter:
    ; (def add #(+ %1 %2))
    ; (def square #(* %1 %1))
    
    ;; Or maybe just:
    ; (def add +)
    • add = -> a, b { a + b }
    • square = -> x { x * x }
    • (ns basics.core)
    • # sigh, if only Ruby supported pipes!
    • result = square.(add.(add.(add.(1,2), 3), 4))
    • (defn add [a b] (+ a b))
    • (defn square [x] (* x x))
    • (def result (-> (add 1 2) (add 3) (add 4) (square)))
    • puts result
    • (println result)
    • ;; It is better (without def), but it is more difficult to test:
    • ; (let [result (-> (add 1 2)
    • ; (add 3)
    • ; (add 4)
    • ; (square))]
    • ; (print result))
    • ;; Shorter:
    • ; (def add #(+ %1 %2))
    • ; (def square #(* %1 %1))
    • ;; Or maybe just:
    • ; (def add +)
Code
Diff
  • from ctypes import *
    
    libc = CDLL("libc.so.6")
    s="Hello Python!\n"
    # for python 2.7.6
    libc.printf(s)
    
    #for python 3.4.3
    for c in s:
      libc.printf(c)
    
    • import sys
    • sys.stdout.write("Hello Python!
    • ")
    • from ctypes import *
    • libc = CDLL("libc.so.6")
    • s="Hello Python!
    • "
    • # for python 2.7.6
    • libc.printf(s)
    • #for python 3.4.3
    • for c in s:
    • libc.printf(c)

Alternatively, you could use eval and implode (alongside a simple conditional statement) to achieve the same thing.

The test fixture used in this Fork is the same as that used in the original Kumite.

Code
Diff
  • // Kumite
    
    function product_of(...$args) {
      return count($args) === 0 ? 1 : eval("return " . implode("*", $args) . ";");
    }
    
    // Test Fixture
    
    $test->describe('The function', function () {
    	$GLOBALS['test']->it('should return 1 when no arguments are passed in', function () {
    		$GLOBALS['test']->assert_equals(product_of(), 1);
    	});
    	$GLOBALS['test']->it('should work for exactly 1 argument', function () {
    		$GLOBALS['test']->assert_equals(product_of(1), 1);
    		$GLOBALS['test']->assert_equals(product_of(2), 2);
    		$GLOBALS['test']->assert_equals(product_of(3), 3);
    		$GLOBALS['test']->assert_equals(product_of(4), 4);
    		$GLOBALS['test']->assert_equals(product_of(5), 5);
    		$GLOBALS['test']->assert_equals(product_of(6), 6);
    		$GLOBALS['test']->assert_equals(product_of(7), 7);
    		$GLOBALS['test']->assert_equals(product_of(8), 8);
    		$GLOBALS['test']->assert_equals(product_of(9), 9);
    		$GLOBALS['test']->assert_equals(product_of(10), 10);
    		$GLOBALS['test']->assert_equals(product_of(13), 13);
    		$GLOBALS['test']->assert_equals(product_of(33), 33);
    	});
    	$GLOBALS['test']->it('should work for an arbitrary numbar of arguments', function () {
    		$GLOBALS['test']->assert_equals(product_of(1, 2, 3, 4, 5), 120);
    		$GLOBALS['test']->assert_equals(product_of(1, 2, 3, 4, 5, 6), 720);
    		$GLOBALS['test']->assert_equals(product_of(4, 5), 20);
    		$GLOBALS['test']->assert_equals(product_of(2, 2, 2, 2, 2, 3, 3, 3), 864);
    		$GLOBALS['test']->assert_equals(product_of(123, 456, 645, 254, 203, 0), 0);
    		$GLOBALS['test']->assert_equals(product_of(2, 2, 2, 2, 2, 2, 2, 2, 2, 2), 1024);
    		$GLOBALS['test']->assert_equals(product_of(0.5, 0.25, 0.125), 0.015625);
    		$GLOBALS['test']->assert_equals(product_of(1, 2, 0.5, 4, 0.25, 8, 0.125, 16, 0.0625, 32, 0.03125), 1.0);
    		$GLOBALS['test']->assert_equals(product_of(5, 6, 7, 8, 9, 10), 151200);
    	});
    });
    • // Kumite
    • function product_of(...$args) {
    • return array_reduce($args, function ($s, $a) {
    • return $s * $a;
    • }, 1);
    • return count($args) === 0 ? 1 : eval("return " . implode("*", $args) . ";");
    • }
    • // Test Fixture
    • $test->describe('The function', function () {
    • $GLOBALS['test']->it('should return 1 when no arguments are passed in', function () {
    • $GLOBALS['test']->assert_equals(product_of(), 1);
    • });
    • $GLOBALS['test']->it('should work for exactly 1 argument', function () {
    • $GLOBALS['test']->assert_equals(product_of(1), 1);
    • $GLOBALS['test']->assert_equals(product_of(2), 2);
    • $GLOBALS['test']->assert_equals(product_of(3), 3);
    • $GLOBALS['test']->assert_equals(product_of(4), 4);
    • $GLOBALS['test']->assert_equals(product_of(5), 5);
    • $GLOBALS['test']->assert_equals(product_of(6), 6);
    • $GLOBALS['test']->assert_equals(product_of(7), 7);
    • $GLOBALS['test']->assert_equals(product_of(8), 8);
    • $GLOBALS['test']->assert_equals(product_of(9), 9);
    • $GLOBALS['test']->assert_equals(product_of(10), 10);
    • $GLOBALS['test']->assert_equals(product_of(13), 13);
    • $GLOBALS['test']->assert_equals(product_of(33), 33);
    • });
    • $GLOBALS['test']->it('should work for an arbitrary numbar of arguments', function () {
    • $GLOBALS['test']->assert_equals(product_of(1, 2, 3, 4, 5), 120);
    • $GLOBALS['test']->assert_equals(product_of(1, 2, 3, 4, 5, 6), 720);
    • $GLOBALS['test']->assert_equals(product_of(4, 5), 20);
    • $GLOBALS['test']->assert_equals(product_of(2, 2, 2, 2, 2, 3, 3, 3), 864);
    • $GLOBALS['test']->assert_equals(product_of(123, 456, 645, 254, 203, 0), 0);
    • $GLOBALS['test']->assert_equals(product_of(2, 2, 2, 2, 2, 2, 2, 2, 2, 2), 1024);
    • $GLOBALS['test']->assert_equals(product_of(0.5, 0.25, 0.125), 0.015625);
    • $GLOBALS['test']->assert_equals(product_of(1, 2, 0.5, 4, 0.25, 8, 0.125, 16, 0.0625, 32, 0.03125), 1.0);
    • $GLOBALS['test']->assert_equals(product_of(5, 6, 7, 8, 9, 10), 151200);
    • });
    • });
Code
Diff
  • (ns codewarssanitycheck)
    
    (defn multiply [ & args ] (apply * args))
    • (ns codewars.sanity.check)
    • (ns codewarssanitycheck)
    • (defn multiply [ & args ] (apply * args))
Code
Diff
  • 
    def sum n
    	n == 1 ? 1 : n + sum(n - 1)
    end
    • def sum n
    • def acc(n, s)
    • return s if n <= 0 # Base case
    • acc(n - 1, s + n) # Recursion step, with accumulator
    • end
    • acc(n, 0)
    • n == 1 ? 1 : n + sum(n - 1)
    • end