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
  • use std::collections::HashMap;
    
    fn first_non_repeating_letter(s: &str) -> Option<char> {
        let mut counts = HashMap::new();
        
        // Count occurrences using lowercase chars to avoid String allocations
        for c in s.chars() {
            let lower = c.to_lowercase().next().unwrap_or(c);
            *counts.entry(lower).or_insert(0) += 1;
        }
        
        // Find the first char in the original string that has a count of 1
        s.chars().find(|&c| {
            let lower = c.to_lowercase().next().unwrap_or(c);
            counts[&lower] == 1
        })
    }
    • use std::collections::HashMap;
    • fn first_non_repeating_letter(s: &str) -> Option<char> {
    • let normalize = |c: char| c.to_lowercase().to_string();
    • let mut appears_twice = HashMap::new();
    • let mut counts = HashMap::new();
    • // Count occurrences using lowercase chars to avoid String allocations
    • for c in s.chars() {
    • appears_twice
    • .entry(normalize(c))
    • .and_modify(|e| *e = true)
    • .or_insert(false);
    • let lower = c.to_lowercase().next().unwrap_or(c);
    • *counts.entry(lower).or_insert(0) += 1;
    • }
    • s.chars().find(|&c| !appears_twice[&normalize(c)])
    • // Find the first char in the original string that has a count of 1
    • s.chars().find(|&c| {
    • let lower = c.to_lowercase().next().unwrap_or(c);
    • counts[&lower] == 1
    • })
    • }
Fundamentals

The string slice indexing makes it a bit clunky, but this works too.

Code
Diff
  • fn get_grade(score: usize) -> &'static str {
        if score <= 100 { &"FFFFFFDCBAA"[score/10..=score/10] } else { "Invalid" }
    }
    • class Kata {
    • public static String getGrade(int s) {
    • return s >= 0 && s <= 100 ? "" + "FFFFFFDCBAA".charAt(s / 10) : "Invalid";
    • }
    • fn get_grade(score: usize) -> &'static str {
    • if score <= 100 { &"FFFFFFDCBAA"[score/10..=score/10] } else { "Invalid" }
    • }

This code is completely nonsense please ignor it

Code
Diff
  • const zero=(a,b)=> 0;
    
    • const zero = (ajith, vijay) => {
    • const sum = ajith + vijay
    • return 0
    • }
    • const zero=(a,b)=> 0;
Code
Diff
  • from re import fullmatch
    from functools import partial, reduce
    
    def compose(*funcs):
        compose_ = lambda f, g: lambda x: f(g(x))
        return reduce(compose_, funcs)
    
    count_valid_usernames = partial(compose(sum, partial(map, bool), partial(map, partial(fullmatch, r"[a-z][a-z0-9]{3,11}"))))
    • from re import fullmatch
    • from functools import partial
    • from functools import partial, reduce
    • def count_valid_usernames(usernames):
    • return sum(map(bool, map(partial(fullmatch, r"[a-z][a-z0-9]{3,11}"), usernames)))
    • def compose(*funcs):
    • compose_ = lambda f, g: lambda x: f(g(x))
    • return reduce(compose_, funcs)
    • count_valid_usernames = partial(compose(sum, partial(map, bool), partial(map, partial(fullmatch, r"[a-z][a-z0-9]{3,11}"))))