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
Algorithms
Logic
Code
Diff
  • flatten = a => a.map ? [].concat(...a.map(flatten)) : a
    • flatten=a=>a.map?[].concat(...a.map(flatten)):a
    • flatten = a => a.map ? [].concat(...a.map(flatten)) : a
Code
Diff
  • function testPassword(password){
      let hasUppercase = false;
      let hasSpecial = false;
      let isLong = false;
      
      password.split('').forEach((char) => {
        let charCode = char.charCodeAt();
        
        if((charCode > 32 && charCode < 48) || (charCode > 57 && charCode < 64)){
          hasSpecial = true;
        } 
        else if(charCode > 64 && charCode < 91){
          hasUppercase = true;
        }
      });
    
      if(password.length > 7){
        isLong = true;
      }
    
      return hasUppercase && isLong && hasSpecial;
    }
    • function testPassword(password){
    • var cap = false;
    • var spec = false;
    • var number = false;
    • var temp;
    • let hasUppercase = false;
    • let hasSpecial = false;
    • let isLong = false;
    • for(i=0;i<password.length;i++){
    • temp = password[i].charCodeAt();
    • if(temp > 32 && temp < 48){
    • spec = true;
    • } else if(temp > 57 && temp < 64){
    • spec = true;
    • } else if(temp > 64 && temp < 91){
    • cap = true;
    • password.split('').forEach((char) => {
    • let charCode = char.charCodeAt();
    • if((charCode > 32 && charCode < 48) || (charCode > 57 && charCode < 64)){
    • hasSpecial = true;
    • }
    • else if(charCode > 64 && charCode < 91){
    • hasUppercase = true;
    • }
    • }
    • });
    • //see if the password is over 8 digits long
    • if(password.length > 7){
    • number = true;
    • }
    • //provide final answer
    • if(cap && number && spec){
    • return true;
    • } else {
    • return false;
    • if(password.length > 7){
    • isLong = true;
    • }
    • return hasUppercase && isLong && hasSpecial;
    • }
Code
Diff
  • class Locale {
      sayHelloTo(whoever){
        throw new Error("Not implemented");
      }
    }
    
    class EnglishLocale extends Locale {
      sayHelloTo(whoever){
        return `hello ${whoever}`;
      }
    }
    
    class PirateLocale extends Locale {
      sayHelloTo(whoever){
        return `yar ${whoever}`;
      }
    }
    
    class BinaryLocale extends EnglishLocale {
      sayHelloTo(whoever) {
        let msg = super.sayHelloTo(whoever);
        return this.txtToBin(msg);
      }
    
      txtToBin(text) {
        let result = [];
    
        for(let character of text){
          let binaryArr = this.numberToBinaryArray(character.charCodeAt());
          result = result.concat(binaryArr);
        }
    
        return result.join("");
      }
      
      numberToBinaryArray(number) {
        let result = [];
    
        while(number > 0){
          let bit = Math.floor(number % 2) != 0 ? 1 : 0;
          result.unshift(bit)
          number = Math.floor(number / 2);
        }
    
        while(result.length != 8) {
          result.unshift(0);
        }
        
        return result;
      }
    }
    
    const GREET_LANG = {
      ENGLISH: new EnglishLocale(),
      PIRATE: new PirateLocale(),
      BINARY: new BinaryLocale(),
    }
    
    const hello = (whoever, lang=GREET_LANG.ENGLISH) => lang.sayHelloTo(whoever);
    • // Declare new languages here and map them in parseGreeting() function
    • const GREET_LANG = {
    • ENGLISH: 0,
    • PIRATE: 1,
    • BINARY: 2
    • class Locale {
    • sayHelloTo(whoever){
    • throw new Error("Not implemented");
    • }
    • }
    • function numberToBinaryArray(number) {
    • let result = [];
    • while(number > 0){
    • let bit = Math.floor(number % 2) != 0 ? 1 : 0;
    • result.unshift(bit)
    • number = Math.floor(number / 2);
    • }
    • while(result.length != 8)
    • result.unshift(0);
    • return result;
    • class EnglishLocale extends Locale {
    • sayHelloTo(whoever){
    • return `hello ${whoever}`;
    • }
    • }
    • function txtToBin(text) {
    • let result = [];
    • for(let character of text){
    • let binaryArr = numberToBinaryArray(character.charCodeAt());
    • result = result.concat(binaryArr);
    • }
    • return result.join("");
    • class PirateLocale extends Locale {
    • sayHelloTo(whoever){
    • return `yar ${whoever}`;
    • }
    • }
    • function parseGreeting(lang) {
    • switch(lang){
    • case GREET_LANG.PIRATE:
    • return 'yar';
    • case GREET_LANG.BINARY:
    • return txtToBin('hello');
    • default:
    • return 'hello';
    • class BinaryLocale extends EnglishLocale {
    • sayHelloTo(whoever) {
    • let msg = super.sayHelloTo(whoever);
    • return this.txtToBin(msg);
    • }
    • }
    • txtToBin(text) {
    • let result = [];
    • for(let character of text){
    • let binaryArr = this.numberToBinaryArray(character.charCodeAt());
    • result = result.concat(binaryArr);
    • }
    • const parseWhoever = (whoever, lang) => lang == GREET_LANG.BINARY ? txtToBin(whoever) : whoever;
    • return result.join("");
    • }
    • numberToBinaryArray(number) {
    • let result = [];
    • while(number > 0){
    • let bit = Math.floor(number % 2) != 0 ? 1 : 0;
    • result.unshift(bit)
    • number = Math.floor(number / 2);
    • }
    • while(result.length != 8) {
    • result.unshift(0);
    • }
    • return result;
    • }
    • }
    • const GREET_LANG = {
    • ENGLISH: new EnglishLocale(),
    • PIRATE: new PirateLocale(),
    • BINARY: new BinaryLocale(),
    • }
    • const hello = (whoever, lang=GREET_LANG.ENGLISH) => `${parseGreeting(lang)} ${parseWhoever(whoever, lang)}`;
    • const hello = (whoever, lang=GREET_LANG.ENGLISH) => lang.sayHelloTo(whoever);
Strings
Data Types

Return the last character from a string.

In Rust return an Option<char>.

Code
Diff
  • fn last_char(string: &str) -> Option<char> {
        string.chars().last()
    }
    • fn last_char(string: &str) -> Option<char> {
    • string.chars().rev().next()
    • string.chars().last()
    • }

?

Code
Diff
  • from math import hypot as hypotenuse
        
    • from math import *
    • def hypotenuse(a, b): return hypot(a,b)
    • from math import hypot as hypotenuse