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
  • fn letter_frequency(s: &str) -> Vec<(char, usize)> {
        let s = s.to_lowercase();
        let mut frequencies: Vec<(char, usize)> = ('a'..='z')
            .map(|l| (l, s.chars().filter(|&c| c == l).count()))
            .filter(|&(_, n)| n != 0)
            .collect();
        frequencies.sort_by_key(|&(_, n)| usize::MAX - n);
        frequencies
    }
    • from collections import Counter
    • def letter_frequency(text):
    • chars = Counter(c for c in text.lower() if c.isalpha())
    • return sorted(chars.items(), key=lambda x: (-x[1], x[0]))
    • fn letter_frequency(s: &str) -> Vec<(char, usize)> {
    • let s = s.to_lowercase();
    • let mut frequencies: Vec<(char, usize)> = ('a'..='z')
    • .map(|l| (l, s.chars().filter(|&c| c == l).count()))
    • .filter(|&(_, n)| n != 0)
    • .collect();
    • frequencies.sort_by_key(|&(_, n)| usize::MAX - n);
    • frequencies
    • }
Code
Diff
  • fn remove_exclamation_marks(s: &str) -> String {
        s.replace('!', "")
    }
    • function removeExclamationMarks(s) {
    • }
    • fn remove_exclamation_marks(s: &str) -> String {
    • s.replace('!', "")
    • }
Functional Programming
Code
Diff
  • fn prime_factors(number: u32) -> Vec<u32> {
        match (2..number).find(|divisor| number % divisor == 0) {
            Some(factor) => [vec![factor], prime_factors(number / factor)].concat(),
            None => vec![number],
        }
    }
    
    • def prime_factors(n):
    • divider = lambda x: next((i for i in range(2, x) if x % i == 0), -1)
    • return ([] if n == 1 else [n]) if divider(n) == -1 else ([divider(n)] + prime_factors(n // divider(n)))
    • fn prime_factors(number: u32) -> Vec<u32> {
    • match (2..number).find(|divisor| number % divisor == 0) {
    • Some(factor) => [vec![factor], prime_factors(number / factor)].concat(),
    • None => vec![number],
    • }
    • }
Code
Diff
  • pub fn is_divisible(n: i32, x: i32, y: i32) -> bool {
        n % x * y == 0
    }
    • pub fn is_divisible(n: i32, x: i32, y: i32) -> bool {
    • n%x+n%y==0
    • n % x * y == 0
    • }
Code
Diff
  • fn calculator(operator: char, num1: i32, num2: i32) -> i32 {
        match operator {
            '+' => num1 + num2,
            '-' => num1 - num2,
            '*' => num1 * num2,
            '/' => num1 / num2,
            _ => panic!("Invalid operator: '{operator}'.")
        }
    }
    • def calculator(operator, num1, num2):
    • if operator == "+":
    • result = num1 + num2
    • elif operator == "-":
    • result = num1 - num2
    • elif operator == "*":
    • result = num1 * num2
    • elif operator == "/":
    • result = num1 / num2
    • else:
    • raise ValueError("Invalid operator. Supported operators are +, -, *, /")
    • return result
    • result = calculator("+", 4, 8)
    • print(result)
    • result = calculator("-", 7, 4)
    • print(result)
    • result = calculator("*", 8, 7)
    • print(result)
    • result = calculator("/", 70, 7)
    • print(result)
    • fn calculator(operator: char, num1: i32, num2: i32) -> i32 {
    • match operator {
    • '+' => num1 + num2,
    • '-' => num1 - num2,
    • '*' => num1 * num2,
    • '/' => num1 / num2,
    • _ => panic!("Invalid operator: '{operator}'.")
    • }
    • }
Code
Diff
  • use std::cmp::Ordering;
    
    fn numbers_vs_letters(s: &str) -> Winner {
        let tallies: Vec<Winner> = s
            .split(" ")
            .map(|group| {
                let number_value = if group.chars().any(|c| c.is_ascii_digit()) {
                    group.chars().filter(char::is_ascii_digit).map(|c| c as u32 - 48).product()
                } else {
                    0
                };
                let letter_value = group.chars().filter(char::is_ascii_alphabetic).map(|c| c as u32 - 96).sum();
                
                match number_value.cmp(&letter_value) {
                    Ordering::Less => Winner::Letters,
                    Ordering::Equal => Winner::Tie,
                    Ordering::Greater => Winner::Numbers,
                }
            })
            .collect();
        
        let number_wins = tallies.iter().filter(|&w| w == &Winner::Numbers).count();
        let letter_wins = tallies.iter().filter(|&w| w == &Winner::Letters).count();
            
        match number_wins.cmp(&letter_wins) {
            Ordering::Less => Winner::Letters,
            Ordering::Equal => Winner::Tie,
            Ordering::Greater => Winner::Numbers,
        }
    }
    
    #[derive(Debug, PartialEq, Eq)]
    enum Winner {
        Numbers,
        Letters,
        Tie,
    }
    • public class pp{
    • use std::cmp::Ordering;
    • fn numbers_vs_letters(s: &str) -> Winner {
    • let tallies: Vec<Winner> = s
    • .split(" ")
    • .map(|group| {
    • let number_value = if group.chars().any(|c| c.is_ascii_digit()) {
    • group.chars().filter(char::is_ascii_digit).map(|c| c as u32 - 48).product()
    • } else {
    • 0
    • };
    • let letter_value = group.chars().filter(char::is_ascii_alphabetic).map(|c| c as u32 - 96).sum();
    • match number_value.cmp(&letter_value) {
    • Ordering::Less => Winner::Letters,
    • Ordering::Equal => Winner::Tie,
    • Ordering::Greater => Winner::Numbers,
    • }
    • })
    • .collect();
    • let number_wins = tallies.iter().filter(|&w| w == &Winner::Numbers).count();
    • let letter_wins = tallies.iter().filter(|&w| w == &Winner::Letters).count();
    • match number_wins.cmp(&letter_wins) {
    • Ordering::Less => Winner::Letters,
    • Ordering::Equal => Winner::Tie,
    • Ordering::Greater => Winner::Numbers,
    • }
    • }
    • #[derive(Debug, PartialEq, Eq)]
    • enum Winner {
    • Numbers,
    • Letters,
    • Tie,
    • }
Code
Diff
  • yearlyElectricCosts=(...c)=>+`${(''+c.reduce((a,b)=>a+b)).split`.`[0]}.${(''+c.reduce((a,b)=>a+b)).split`.`[1].slice(0,2)}`
    • yearlyElectricCosts=(...c)=>(r=>+`${r[0]}.${r[1].slice(0,2)}`)((''+c.reduce((a,b)=>a+b)).split`.`)
    • yearlyElectricCosts=(...c)=>+`${(''+c.reduce((a,b)=>a+b)).split`.`[0]}.${(''+c.reduce((a,b)=>a+b)).split`.`[1].slice(0,2)}`
Code
Diff
  • public static class Kata 
    {
        public static int SameCase(char a, char b) =>
            (a >= 65 && a <= 90 || a >= 97 && a <= 122)
                ? (b >= 65 && b <= 90 || b >= 97 && b <= 122)
                    ? (a >= 97 && b >= 97 || a <= 90 && b <= 90)
                        ? 1
                        : 0
                    : -1
                : -1;
    }
    • public static class Kata
    • {
    • public static int SameCase(char a, char b) =>
    • (!(char.IsLetter(a) && char.IsLetter(b)))
    • ? -1
    • : (char.IsLower(a) == char.IsLower(b))
    • ? 1
    • : 0;
    • public static int SameCase(char a, char b) =>
    • (a >= 65 && a <= 90 || a >= 97 && a <= 122)
    • ? (b >= 65 && b <= 90 || b >= 97 && b <= 122)
    • ? (a >= 97 && b >= 97 || a <= 90 && b <= 90)
    • ? 1
    • : 0
    • : -1
    • : -1;
    • }