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 Calculator(expression):
        try:
            return eval(expression)
        except:
            return 0
    
    • def Calculator(operator: str = "+", arg1: float = 0, arg2: float = 0):
    • def Calculator(expression):
    • try:
    • return eval(f"{arg1} {operator} {arg2}")
    • return eval(expression)
    • except:
Strings
Mathematics

Make the matching of the operator character more readable

Code
Diff
  • fn math(s: &str) -> i32 {
        // remove whitespace characters so all we have left are digits and the operator
        let math_str: String = s.chars().filter(|ch| !ch.is_whitespace()).collect();
        
        // find the position of the operator character
        let pos: usize = math_str    
            .chars()
            .position(|ch| match ch {
                '+' | '-' | '*' | '/' | '=' => true,
                _ => false
            })
            .expect("invalid operator, expected +, -, *, / or =");
        
        // extract the two numbers from the string
        let num1: i32 = math_str[..pos].parse().unwrap();
        let num2: i32 = math_str[pos + 1..].parse().unwrap();
        
        match &math_str[pos..=pos] {
            "+" => num1 + num2,
            "-" => num1 - num2,
            "*" => num1 * num2,
            "/" => num1 / num2,
            _ => (num1 == num2) as i32,
        }
    }
    • fn math(s: &str) -> i32 {
    • // remove whitespace characters so all we have left are digits and the operator
    • let math_str: String = s.chars().filter(|ch| !ch.is_whitespace()).collect();
    • // find the position of the operator character
    • let pos: usize = math_str
    • .chars()
    • .position(|ch| ch == '+' || ch == '-' || ch == '*' || ch == '/' || ch == '=')
    • .position(|ch| match ch {
    • '+' | '-' | '*' | '/' | '=' => true,
    • _ => false
    • })
    • .expect("invalid operator, expected +, -, *, / or =");
    • // extract the two numbers from the string
    • let num1: i32 = math_str[..pos].parse().unwrap();
    • let num2: i32 = math_str[pos + 1..].parse().unwrap();
    • match &math_str[pos..pos + 1] {
    • match &math_str[pos..=pos] {
    • "+" => num1 + num2,
    • "-" => num1 - num2,
    • "*" => num1 * num2,
    • "/" => num1 / num2,
    • _ => (num1 == num2) as i32,
    • }
    • }
Code
Diff
  • var tr = {
      "I": 1,
      "V": 5,
      "X": 10,
      "L": 50,
      "C": 100,
      "D": 500,
      "M": 1000
    }
    
    function solution (roman_string) {
    	return roman_string.split('').map((letter, index, a) => {
        const current_value = tr[letter];
        const next_value = tr[a[index+1]];
        return next_value && current_value < next_value ? 
          (- current_value) : current_value;
      }).reduce((acc, item) => acc + item, 0);
    }
    • var tr = {
    • "I": 1,
    • "V": 5,
    • "X": 10,
    • "L": 50,
    • "C": 100,
    • "D": 500,
    • "M": 1000
    • }
    • function solution (roman) {
    • letters = roman.split('');
    • var res = 0;
    • letters.forEach((cur, i) => {
    • var next = letters[i + 1];
    • if (tr[next] && tr[cur] < tr[next]) {
    • res -= tr[cur];
    • } else {
    • res += tr[cur];
    • }
    • })
    • return res;
    • function solution (roman_string) {
    • return roman_string.split('').map((letter, index, a) => {
    • const current_value = tr[letter];
    • const next_value = tr[a[index+1]];
    • return next_value && current_value < next_value ?
    • (- current_value) : current_value;
    • }).reduce((acc, item) => acc + item, 0);
    • }