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
Puzzles
Logic
Code
Diff
  • fn coffee_and_code(coffee: bool, weekend: bool, hour: u8, code: u8) -> bool {
        matches!(
            (coffee, weekend, hour, code),
            (true, true, ..=6 | 22.., 40..=76)
        )
    }
    
    • def coffee_and_code(coffee, weekend, hour, code):
    • pass
    • fn coffee_and_code(coffee: bool, weekend: bool, hour: u8, code: u8) -> bool {
    • matches!(
    • (coffee, weekend, hour, code),
    • (true, true, ..=6 | 22.., 40..=76)
    • )
    • }
Code
Diff
  • fn main() {
        let mut a = 1;
        a = 10;
    }
    
    • var a = 1;
    • //Change the Variable 'a' to 10;
    • fn main() {
    • let mut a = 1;
    • a = 10;
    • }
Code
Diff
  • fn balanced_parenthesis(s: &str) -> String {
        let balanced = s
            .chars()
            .fold(
                Some(0u32),
                |acc, c|
                    match c {
                        '(' => acc.map(|n| n + 1),
                        ')' => acc.and_then(|n| n.checked_sub(1)),
                        _ => acc
                    }
            ) == Some(0);
        
        if balanced {
            "Balanced"
        } else {
            "Unbalanced"
        }.into()
    }
    • function balanced_parenthesis(s) {
    • if(s == null) return null;
    • fn balanced_parenthesis(s: &str) -> String {
    • let balanced = s
    • .chars()
    • .fold(
    • Some(0u32),
    • |acc, c|
    • match c {
    • '(' => acc.map(|n| n + 1),
    • ')' => acc.and_then(|n| n.checked_sub(1)),
    • _ => acc
    • }
    • ) == Some(0);
    • var i = 0,
    • startCnt = 0,
    • n = s.length;
    • for(i = 0; i < n; i++) {
    • if(s[i] === "(") {
    • startCnt += 1;
    • } else if(s[i] === ")") {
    • startCnt -= 1;
    • if(startCnt < 0) {
    • break;
    • }
    • }
    • }
    • if(startCnt !== 0) {
    • return 'Unbalanced';
    • if balanced {
    • "Balanced"
    • } else {
    • return 'Balanced';
    • }
    • "Unbalanced"
    • }.into()
    • }
Code
Diff
  • fn main() {
        "!TSUr OLLEh"
            .chars()
            .rev()
            .map(|c|
                if c.is_uppercase() {
                    c.to_ascii_lowercase()
                } else {
                    c.to_ascii_uppercase()
                }
            )
            .for_each(|c| print!("{c}"));
    }
    • fn main() {
    • let name = "Rust";
    • println!("Hello, {}!", name);
    • "!TSUr OLLEh"
    • .chars()
    • .rev()
    • .map(|c|
    • if c.is_uppercase() {
    • c.to_ascii_lowercase()
    • } else {
    • c.to_ascii_uppercase()
    • }
    • )
    • .for_each(|c| print!("{c}"));
    • }
Fundamentals
Strings

Task: Define a function that takes a string as a parameter and returns it with spaces between each original character

Code
Diff
  • #include <string>
    
    std::string digest(std::string param)
    {
        for (int i = 1; i < param.length(); i += 2)
          param.insert(i, 1, ' ');
        return param;
    }
    • #include <string.h>
    • std::string digest(std::string param) {
    • std::string result;
    • for (int i = 0; sizeof(param); i++) {
    • result += param[i];
    • result += ' ';
    • }
    • return result;
    • } //Please fix!
    • #include <string>
    • std::string digest(std::string param)
    • {
    • for (int i = 1; i < param.length(); i += 2)
    • param.insert(i, 1, ' ');
    • return param;
    • }
Code
Diff
  • const numMinusSeven = num => {
      let youGoodBro = [];
      while(num > 0) youGoodBro.push(num -= 7);
      return youGoodBro.length;
    }
    • const numMinusSeven = function(num) {
    • const numMinusSeven = num => {
    • let youGoodBro = [];
    • while (num > 0) {
    • num -= 7;
    • youGoodBro.push(num);
    • }
    • while(num > 0) youGoodBro.push(num -= 7);
    • return youGoodBro.length;
    • }
Algorithms
Code
Diff
  • fn digits(mut n: u64) -> usize {
        std::iter::from_fn(|| { n /= 10; (n != 0).then_some(n) }).count() + 1
    }
    • use std::collections::BTreeMap;
    • fn digits(n: u64) -> usize {
    • let powers = (0..20).map(|n| (
    • if n == 0 { 0 } else { 10_u64.pow(n) },
    • n as usize + 1
    • )).collect::<BTreeMap<_, _>>();
    • return *powers.range(..=n).last().unwrap().1;
    • fn digits(mut n: u64) -> usize {
    • std::iter::from_fn(|| { n /= 10; (n != 0).then_some(n) }).count() + 1
    • }
Code
Diff
  • public static class Kata 
    {
      public static int SameCase(char a, char b)
      {
        if (!char.IsLetter(a) || !char.IsLetter(b))
        {
          return -1;
        }
    
        return char.IsUpper(a) == char.IsUpper(b) ? 1 : 0;
      }
    }
    // 3ms faster :)
    • public static class Kata
    • {
    • public static int SameCase(char a, char b) =>
    • char.IsLetter(a) && char.IsLetter(b)
    • ? char.IsUpper(a) == char.IsUpper(b)
    • ? 1 : 0
    • : -1;
    • }
    • public static int SameCase(char a, char b)
    • {
    • if (!char.IsLetter(a) || !char.IsLetter(b))
    • {
    • return -1;
    • }
    • return char.IsUpper(a) == char.IsUpper(b) ? 1 : 0;
    • }
    • }
    • // 3ms faster :)
Code
Diff
  • def verify_sum(a, b)
      return false if a.nil? || b.nil?
      
      a.sum == b.sum
    end
    
    • def verify_sum(a, b)
    • return a.sum == b.sum unless a.nil? || b.nil?
    • 'a' == 'b'
    • return false if a.nil? || b.nil?
    • a.sum == b.sum
    • end
Code
Diff
  • from ast import literal_eval
    from random import choice
    
    def int_(text):
        number = int(text)
        return number
    
    def eval_(text):
        number = eval(text)
        return number
    
    def lit_(text):
        number = literal_eval(text)
        return number
    
    def dig_(text):
        number = 0
        chars = [*text]
        digits = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
        while chars:
            char = chars.pop(0)
            number = number * 10 + digits.index(char)
        return number
    
    methods = [int_, eval_, lit_, dig_]
    
    def x(text):
        if not isinstance(text, str):
            return None
        if text[0] == '-':
            text = text[1:]
            sign = -1
        else:
            sign = 1
        if not text.isdigit():
            return None
        function = choice(methods)
        number = function(text)
        number *= sign
        return number
    • x=int
    • from ast import literal_eval
    • from random import choice
    • def int_(text):
    • number = int(text)
    • return number
    • def eval_(text):
    • number = eval(text)
    • return number
    • def lit_(text):
    • number = literal_eval(text)
    • return number
    • def dig_(text):
    • number = 0
    • chars = [*text]
    • digits = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
    • while chars:
    • char = chars.pop(0)
    • number = number * 10 + digits.index(char)
    • return number
    • methods = [int_, eval_, lit_, dig_]
    • def x(text):
    • if not isinstance(text, str):
    • return None
    • if text[0] == '-':
    • text = text[1:]
    • sign = -1
    • else:
    • sign = 1
    • if not text.isdigit():
    • return None
    • function = choice(methods)
    • number = function(text)
    • number *= sign
    • return number