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
Code
Diff
  • function dumbRockPaperScissors(player1, player2) {
        let size1 = 0;
        for (let i = 0; i < player1.length; i++) {
            for (let j = 0; j < player1.length; j++) {
                if (i === j) {
                    size1++;
                }
            }
        }
    
        let size2 = 0;
        for (let i = 0; i < player2.length; i++) {
            for (let j = 0; j < player2.length; j++) {
                if (i === j) {
                    size2++;
                }
            }
        }
    
        if (size1 === size2) {
            return 'Draw';
        }
    
        if (size1 > size2) {
            if (
                (player1 === 'Rock' && player2 === 'Scissors') ||
                (player1 === 'Scissors' && player2 === 'Paper') ||
                (player1 === 'Paper' && player2 === 'Rock')
            ) {
                return 'Player 1 wins';
            } else {
                return 'Player 2 wins';
            }
        } else {
            if (
                (player2 === 'Rock' && player1 === 'Scissors') ||
                (player2 === 'Scissors' && player1 === 'Paper') ||
                (player2 === 'Paper' && player1 === 'Rock')
            ) {
                return 'Player 2 wins';
            } else {
                return 'Player 1 wins';
            }
        }
    }
    
    • function dumbRockPaperScissors(player1, player2) {
    • let size1 = 0;
    • for (let i = 0; i < player1.length; i++) {
    • for (let j = 0; j < player1.length; j++) {
    • if (i === j) {
    • size1++;
    • }
    • }
    • }
    • }
    • let size2 = 0;
    • for (let i = 0; i < player2.length; i++) {
    • for (let j = 0; j < player2.length; j++) {
    • if (i === j) {
    • size2++;
    • }
    • }
    • }
    • if (size1 === size2) {
    • return 'Draw';
    • }
    • if (size1 > size2) {
    • if (
    • (player1 === 'Rock' && player2 === 'Scissors') ||
    • (player1 === 'Scissors' && player2 === 'Paper') ||
    • (player1 === 'Paper' && player2 === 'Rock')
    • ) {
    • return 'Player 1 wins';
    • } else {
    • return 'Player 2 wins';
    • }
    • } else {
    • if (
    • (player2 === 'Rock' && player1 === 'Scissors') ||
    • (player2 === 'Scissors' && player1 === 'Paper') ||
    • (player2 === 'Paper' && player1 === 'Rock')
    • ) {
    • return 'Player 2 wins';
    • } else {
    • return 'Player 1 wins';
    • }
    • }
    • }
Code
Diff
  • const firstNonRepeatingCharacter = (str) => {
        const charCounts = new Map();
    
        for (let i = 0; i < str.length; i++) {
            charCounts.set(str[i], (charCounts.get(str[i]) || 0) + 1);
        }
    
        for (let i = 0; i < str.length; i++) {
            if (charCounts.get(str[i]) === 1) {
                return str[i];
            }
        }
    
        return null;
    };
    
    // def first_non_repeating_character(str)
    //   char_counts = Hash.new(0)
    
    //   str.each_char { |char| char_counts[char] += 1 }
    
    //   str.each_char do |char|
    //     return char if char_counts[char] == 1
    //   end
    
    //   nil
    // end
    • const firstNonRepeatingCharacter = (str) => {
    • const charCounts = new Map();
    • for (let i = 0; i < str.length; i++) {
    • let seenDuplicate = false;
    • for (let j = 0; j < str.length; j++) {
    • if (str[i] === str[j] && i !== j) {
    • seenDuplicate = true;
    • break;
    • }
    • }
    • if (!seenDuplicate) {
    • charCounts.set(str[i], (charCounts.get(str[i]) || 0) + 1);
    • }
    • for (let i = 0; i < str.length; i++) {
    • if (charCounts.get(str[i]) === 1) {
    • return str[i];
    • }
    • }
    • return null; // return null if no unique character is found
    • };
    • return null;
    • };
    • // def first_non_repeating_character(str)
    • // char_counts = Hash.new(0)
    • // str.each_char { |char| char_counts[char] += 1 }
    • // str.each_char do |char|
    • // return char if char_counts[char] == 1
    • // end
    • // nil
    • // end
Code
Diff
  • var sum = (a, b) => a + b;
    • function sum(a,b) {
    • return a+b; // wrong returning
    • }
    • var sum = (a, b) => a + b;
Code
Diff
  • function digitToText(digit) {
      return ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'][digit]
    }
    • const nums = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
    • function digitToText(digit) {
    • return nums[digit]
    • return ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'][digit]
    • }
Code
Diff
  • def multiply(a,b):
        return a*b
    
    • from math import prod
    • def multiply(a, b):
    • ints = (a, b)
    • return prod(ints)
    • result = multiply(5, 10)
    • print(result)
    • def multiply(a,b):
    • return a*b
Algorithms
Code
Diff
  • fn digits(mut n: u64) -> usize {
        std::iter::from_fn(|| { n /= 10; Some(n) })
            .take_while(|&n| n > 0)
            .count() + 1
    }
    • fn digits(mut n: u64) -> usize {
    • std::iter::from_fn(|| { n = n / 10; Some(n) }).
    • take_while(|n| *n > 0)
    • std::iter::from_fn(|| { n /= 10; Some(n) })
    • .take_while(|&n| n > 0)
    • .count() + 1
    • }
Code
Diff
  • use std::ops::Shr;
    fn div2<T: Shr<i32, Output = T>>(a: T) -> T {
        a >> 1
    }
    • unsigned long long div2(unsigned long long a){
    • //Use binary operators...I-O
    • return a >> 1;
    • use std::ops::Shr;
    • fn div2<T: Shr<i32, Output = T>>(a: T) -> T {
    • a >> 1
    • }
Code
Diff
  • const tab = (f, a, b, h) => {
      return [...Array((b - a) / h + 1).keys()]
        .map(n => f(n * h + a))
        .reduce((n, p) => n + p, 0);
    }
    • const tab = (f, a, b, h) => {
    • return [...Array((b - a) / h + 1).keys()]
    • .map(n => f(n * h + a))
    • .reduce((n, p) => n + p, 0);
    • }