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
  • def power(num, p):
        return num ** p
    • def power(num, p):
    • output = num ** p
    • return output
    • return num ** p
Code
Diff
  • const isDivisible = (n,a,b, truth = n % a === 0 && n % b === 0) => truth;
    
    • const isDivisible = (n,...args) => args.every(arg => n % arg == 0);
    • const isDivisible = (n,a,b, truth = n % a === 0 && n % b === 0) => truth;
Code
Diff
  • const accents = 'áéíóú',
          chars = 'abcdefghijklmnopqrstuvwxyz',
          a = 'bcdfghijklmnpqrstuvwxyzñ',
          b = 'aeilorsuy',
          c = 'aeioruhtlkkkkkkkkk',
          d = 'aeiourldns',
          e = 'abcdefyrnsltmpxizñ',
          f = 'aeiouylrf',
          g = 'aeiouhrlmns',
          h = 'aeiourlt',
          i = 'encstoadlmvzrgfrtpbkñ',
          j = 'uaoei',
          k = 'eiaolunyhsrw',
          l = 'eiayoug',
          m = 'aeiouypb',
          n = 'aeiouytgdcsn',
          o = 'abcdefnruplsmtzñ',
          p = 'rehaoilhtusp',
          q = 'u',
          r = 'aeioutymscdrnpb',
          s = 'etshaicupomlynk',
          t = 'eiraohuytlar',
          u = 'bcdfghnslrmtiaepzñ',
          v = 'eiaour',
          w = 'aeiouyhrnls',
          x = 'aeiouytcpl',
          y = 'elstacpnm',
          z = 'eaioyuz',
          ñ = 'aeiou';
    
    const rando = () => {
      try {
        let crypto
        try {
          crypto = require('crypto').randomFillSync
        } catch (_) {
          crypto = (window.crypto || window.msCrypto).getRandomValues
        }
        let cryptoRandoms
        const cryptoRandomSlices = []
        let cryptoRandom
        while ((cryptoRandom = '.' + cryptoRandomSlices.join('')).length < 30) {
          cryptoRandoms = crypto(new Uint32Array(5))
          for (let i = 0; i < cryptoRandoms.length; i++) {
            const cryptoRandomSlice = cryptoRandoms[i] < 4000000000 ? cryptoRandoms[i].toString().slice(1) : ''
            if (cryptoRandomSlice.length > 0) cryptoRandomSlices[cryptoRandomSlices.length] = cryptoRandomSlice
          }
        }
        return Number(cryptoRandom)
      } catch (_) {
        return Math.random()
      }
    }
    
    function rng (doAccents = true, min = 4, max = 8, length = Math.floor(rando() * (max - min + 1)) + min, firstChar = chars[Math.floor(rando() * chars.length)]) {
      let out = [];
      
      for (let index = 0; index < length; index++) {
        if (index == 0) {
          out.push(firstChar);
        } else {
          out.push(eval(out[index-1])[Math.floor(rando() * eval(out[index-1]).length)]);
        }
      }
      
      if (doAccents) {
        out = addAccents(out);
      }
      
      if (out[out.length-1] == "ñ") {
        out.push(ñ[Math.floor(rando() * ñ.length)]);
      }
      
      return [out[0].toUpperCase(), ...out.slice(1)].join('');
    }
    
    function addAccents(arr) {
      let hasAccent = false;
      let outVowels = arr.filter(a => ñ.includes(a));
      let lastVowel = outVowels[outVowels.length-1];
      
      for (let i = 0; i < arr.length; i++) {
        let char = arr[i];
        let newChar;
        
        if (rando() >= 0.5 && !hasAccent && ñ.includes(char)) {
          newChar = accents[ñ.indexOf(char)];
          hasAccent = true;
        } else if (lastVowel == char && !hasAccent) {
          newChar = accents[ñ.indexOf(char)];
          hasAccent = true;
        }
        
        arr[i] = newChar || char;
      }
      return arr;
    }
    
    for(let i = 0; i < 10; i++) {
      console.log(rng(true, 5, 6));
      console.log("");
      console.log(rng(false, 4, 8));
      console.log("");
    }
    
    // good names: garnguck, lemock, wemee, yermpoo, jelifyeshi, vazaji, zufazi, dupunt, trythluid
    
    /* more good names:
      elóra, yáddro, lezíe, janeño, bahúz, gouñuña,
      volgrad, flizz, tunck, vorag, sylem, kitala, vunos, jaith, qumor, henup, ornda, zilep, cantadu, gromu, lodley
    */
    
    
    • const accents = 'áéíóú',
    • chars = 'abcdefghijklmnopqrstuvwxyz',
    • a = 'bcdfghijklmnpqrstuvwxyzñ',
    • b = 'aeilorsuy',
    • c = 'aeioruhtlkkkkkkkkk',
    • d = 'aeiourldns',
    • e = 'abcdefyrnsltmpxizñ',
    • f = 'aeiouylrf',
    • g = 'aeiouhrlmns',
    • h = 'aeiourlt',
    • i = 'encstoadlmvzrgfrtpbkñ',
    • j = 'uaoei',
    • k = 'eiaolunyhsrw',
    • l = 'eiayoug',
    • m = 'aeiouypb',
    • n = 'aeiouytgdcsn',
    • o = 'abcdefnruplsmtzñ',
    • p = 'rehaoilhtusp',
    • q = 'u',
    • r = 'aeioutymscdrnpb',
    • s = 'etshaicupomlynk',
    • t = 'eiraohuytlar',
    • u = 'bcdfghnslrmtiaepzñ',
    • v = 'eiaour',
    • w = 'aeiouyhrnls',
    • x = 'aeiouytcpl',
    • y = 'elstacpnm',
    • z = 'eaioyuz',
    • ñ = 'aeiou';
    • function rng (doAccents = true, min = 4, max = 8, length = Math.floor(Math.random() * (max - min + 1)) + min, firstChar = chars[Math.floor(Math.random() * chars.length)]) {
    • const rando = () => {
    • try {
    • let crypto
    • try {
    • crypto = require('crypto').randomFillSync
    • } catch (_) {
    • crypto = (window.crypto || window.msCrypto).getRandomValues
    • }
    • let cryptoRandoms
    • const cryptoRandomSlices = []
    • let cryptoRandom
    • while ((cryptoRandom = '.' + cryptoRandomSlices.join('')).length < 30) {
    • cryptoRandoms = crypto(new Uint32Array(5))
    • for (let i = 0; i < cryptoRandoms.length; i++) {
    • const cryptoRandomSlice = cryptoRandoms[i] < 4000000000 ? cryptoRandoms[i].toString().slice(1) : ''
    • if (cryptoRandomSlice.length > 0) cryptoRandomSlices[cryptoRandomSlices.length] = cryptoRandomSlice
    • }
    • }
    • return Number(cryptoRandom)
    • } catch (_) {
    • return Math.random()
    • }
    • }
    • function rng (doAccents = true, min = 4, max = 8, length = Math.floor(rando() * (max - min + 1)) + min, firstChar = chars[Math.floor(rando() * chars.length)]) {
    • let out = [];
    • for (let index = 0; index < length; index++) {
    • if (index == 0) {
    • out.push(firstChar);
    • } else {
    • out.push(eval(out[index-1])[Math.floor(Math.random() * eval(out[index-1]).length)]);
    • out.push(eval(out[index-1])[Math.floor(rando() * eval(out[index-1]).length)]);
    • }
    • }
    • if (doAccents) {
    • out = addAccents(out);
    • }
    • if (out[out.length-1] == "ñ") {
    • out.push(ñ[Math.floor(Math.random() * ñ.length)]);
    • out.push(ñ[Math.floor(rando() * ñ.length)]);
    • }
    • return out.join('');
    • return [out[0].toUpperCase(), ...out.slice(1)].join('');
    • }
    • function addAccents(arr) {
    • let hasAccent = false;
    • let outVowels = arr.filter(a => ñ.includes(a));
    • let lastVowel = outVowels[outVowels.length-1];
    • for (let i = 0; i < arr.length; i++) {
    • let char = arr[i];
    • let newChar;
    • if (Math.random() >= 0.5 && !hasAccent && ñ.includes(char)) {
    • if (rando() >= 0.5 && !hasAccent && ñ.includes(char)) {
    • newChar = accents[ñ.indexOf(char)];
    • hasAccent = true;
    • } else if (lastVowel == char && !hasAccent) {
    • newChar = accents[ñ.indexOf(char)];
    • hasAccent = true;
    • }
    • arr[i] = newChar || char;
    • }
    • return arr;
    • }
    • for(let i = 0; i < 10; i++) {
    • console.log(rng(true, 5, 6));
    • console.log("");
    • console.log(rng(false, 4, 8));
    • console.log("");
    • }
    • // good names: garnguck, lemock, wemee, yermpoo, jelifyeshi, vazaji, zufazi, dupunt, trythluid
    • /* more good names:
    • elóra, yáddro, lezíe, janeño, bahúz, gouñuña,
    • volgrad, flizz, tunck, vorag, sylem, kitala, vunos, jaith, qumor, henup, ornda, zilep, cantadu, gromu, lodley
    • */

Added some more test cases.

Code
Diff
  • int reverse_int_recc(int num, int rev) {
        return num ? reverse_int_recc(num / 10, rev * 10 + (num % 10)): rev;
    }
    
    int reverse_int(int num) {
        return reverse_int_recc(num, 0);
    }
    
    • int reverse_int_recc(int num, int rev) {
    • return (num == 0) ? rev : reverse_int_recc(num / 10, rev * 10 + (num % 10));
    • return num ? reverse_int_recc(num / 10, rev * 10 + (num % 10)): rev;
    • }
    • int reverse_int(int num) {
    • return reverse_int_recc(num, 0);
    • }
Code
Diff
  • find_first_sub_string=lambda text,sub:[None, index:=text.find(sub)][index>-1]
    • find_first_sub_string = lambda text, sub: next(filter(lambda x: x>-1, [text.find(sub)]), None)
    • find_first_sub_string=lambda text,sub:[None, index:=text.find(sub)][index>-1]
Code
Diff
  • remove = lambda i, v: list(filter(lambda x: x not in v, i))
    • def remove(integers, values):
    • return [i for i in integers if i not in values]
    • remove = lambda i, v: list(filter(lambda x: x not in v, i))
Code
Diff
  • export function validateString(input: string, index: number): boolean {
      const validator = new BracketsValidator();
      return [...input].splice(index, input.length-index).every(e=>validator.isValidChar(e));
    }
    
    class BracketsValidator {
      private readonly bracketPairs: Record<string, string> = {
        '{': '}',
        '[': ']',
        '(': ')',
      };
      private readonly openBrackets: Set<string> = new Set(Object.keys(this.bracketPairs));
      private readonly closingBrackets: Set<string> = new Set(Object.values(this.bracketPairs));
      private stack: string[] = [];
      
      public isValidChar(char: string): boolean {
        if (this.isNotBracket(char)) {
          return true;
        }
        
        if (this.isOpeningBracket(char)) {
          this.push(char);
          return true;
        }
        
        if (this.hasMatchFor(char)) {
          this.pop();
          return true;
        }
        
        return false;
      }
      
      private push(bracket: string): void {
        this.stack.push(bracket);
      } 
      
      private pop(): string|undefined {
        return this.stack.pop();
      }
      
      private lastFromStack(): string|undefined {
        return this.stack.slice(-1)[0];
      }
      
      private hasMatchFor(bracket: string): boolean {
        const previousBracket: string|undefined = this.lastFromStack();
        
        if (undefined === previousBracket) {
          return false;
        }
        
        const match = this.matchFor(bracket);
        
        return previousBracket === match;
      }
      
      private isOpeningBracket(char: string): boolean {
          return this.openBrackets.has(char);
      }
      
      private isClosingBracket(char: string): boolean {
        return this.closingBrackets.has(char)
      }
      
      private isNotBracket(char: string): boolean {
      return !(this.isOpeningBracket(char)||this.isClosingBracket(char));
      }
      
      private matchFor(bracket: string): string {
        const index: number = Object.values(this.bracketPairs).indexOf(bracket);
        return Object.keys(this.bracketPairs)[index];
      }
    }
    
    • export function validateString(input: string, index: number): boolean {
    • const validator = new BracketsValidator();
    • for (let i = index; i < input.length; i++) {
    • const char = input[i];
    • if (!validator.isValidChar(char)) {
    • return false;
    • }
    • }
    • return true;
    • return [...input].splice(index, input.length-index).every(e=>validator.isValidChar(e));
    • }
    • class BracketsValidator {
    • private readonly bracketPairs: Record<string, string> = {
    • '{': '}',
    • '[': ']',
    • '(': ')',
    • };
    • private readonly openBrackets: Set<string> = new Set(Object.keys(this.bracketPairs));
    • private readonly closingBrackets: Set<string> = new Set(Object.values(this.bracketPairs));
    • private stack: string[] = [];
    • public isValidChar(char: string): boolean {
    • if (this.isNotBracket(char)) {
    • return true;
    • }
    • if (this.isOpeningBracket(char)) {
    • this.push(char);
    • return true;
    • }
    • if (this.hasMatchFor(char)) {
    • this.pop();
    • return true;
    • }
    • return false;
    • }
    • private push(bracket: string): void {
    • this.stack.push(bracket);
    • }
    • private pop(): string|undefined {
    • return this.stack.pop();
    • }
    • private lastFromStack(): string|undefined {
    • return this.stack.slice(-1)[0];
    • }
    • private hasMatchFor(bracket: string): boolean {
    • const previousBracket: string|undefined = this.lastFromStack();
    • if (undefined === previousBracket) {
    • return false;
    • }
    • const match = this.matchFor(bracket);
    • if (previousBracket !== match) {
    • return false;
    • }
    • return true;
    • return previousBracket === match;
    • }
    • private isOpeningBracket(char: string): boolean {
    • if (this.openBrackets.has(char)) {
    • return true;
    • }
    • return false;
    • return this.openBrackets.has(char);
    • }
    • private isClosingBracket(char: string): boolean {
    • if (this.closingBrackets.has(char)) {
    • return true;
    • }
    • return false;
    • return this.closingBrackets.has(char)
    • }
    • private isNotBracket(char: string): boolean {
    • if (this.isOpeningBracket(char)) {
    • return false;
    • }
    • if (this.isClosingBracket(char)) {
    • return false;
    • }
    • return true;
    • return !(this.isOpeningBracket(char)||this.isClosingBracket(char));
    • }
    • private matchFor(bracket: string): string {
    • const index: number = Object.values(this.bracketPairs).indexOf(bracket);
    • return Object.keys(this.bracketPairs)[index];
    • }
    • }