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 number_of_primes(n):
        p, i = [], 2
        while len(p) < n:
            if all(i % d for d in range(2, int(i**0.5) + 1)):
                p.append(i)
            i += 1
        return p
    • def pri(n):
    • return n == 2 or n % 2 and n > 2 and all(n % i for i in range(3, int(n ** .5) + 1, 2))
    • def Number_of_Primes(n):
    • if not isinstance(n, int) or n < 0:
    • return "Invalid input"
    • prime = [2]
    • i = 3
    • while len(prime) < n:
    • if pri(i):
    • prime.append(i)
    • i += 2
    • return prime
    • def number_of_primes(n):
    • p, i = [], 2
    • while len(p) < n:
    • if all(i % d for d in range(2, int(i**0.5) + 1)):
    • p.append(i)
    • i += 1
    • return p
Code
Diff
  • def cheat_code(func):
        def wrapper(db, user, password):
            db[user] = password
            return func(db, user, password)
        return wrapper
    
    
    def login_kumite(user_db, username, password):
        if username in user_db and user_db[username] == password:
            print("Login successful!")
            return True
        else:
            print("Invalid username or password.")
            return False
    
    • def cheat_code(func):
    • pass
    • def wrapper(db, user, password):
    • db[user] = password
    • return func(db, user, password)
    • return wrapper
    • def login_kumite(user_db, username, password):
    • pass
    • if username in user_db and user_db[username] == password:
    • print("Login successful!")
    • return True
    • else:
    • print("Invalid username or password.")
    • return False
Code
Diff
  • fn find_the_longest_word(sentence: &str) -> Option<&str> {
        let words: Vec<&str> = sentence.split_whitespace().collect();
        let max_len = words.iter().map(|word| word.len()).max()?;
    
        let longest_words: Vec<&str> = words.into_iter().filter(|&word| word.len() == max_len).collect();
    
        if longest_words.len() > 1 {
            None
        } else {
            longest_words.get(0).copied()
        }
    }
    • fn find_the_longest_word(sentence: &str) -> Option<&str> {
    • let max_len = sentence.split_whitespace().map(str::len).max()?;
    • let mut max_words = sentence.split_whitespace().filter(|word| word.len() == max_len);
    • let first_max = max_words.next();
    • let second_max = max_words.next();
    • if second_max.is_some() {
    • return None;
    • }
    • first_max
    • }
    • let words: Vec<&str> = sentence.split_whitespace().collect();
    • let max_len = words.iter().map(|word| word.len()).max()?;
    • let longest_words: Vec<&str> = words.into_iter().filter(|&word| word.len() == max_len).collect();
    • if longest_words.len() > 1 {
    • None
    • } else {
    • longest_words.get(0).copied()
    • }
    • }
Algorithms
Arrays
Mathematics
Geometry
Code
Diff
  • makeMove
    
        =(c,s)=>
    
            [...s].reduce((r,d)=>[r[0]+(d=='r')-(d=='l'),r[1]+(d=='t')-(d=='b')],c)
    • function makeMove(init, sequence) {
    • let coords = [...init];
    • for(const dir of sequence) {
    • coords[0] += (dir == 'r') - (dir == 'l');
    • coords[1] += (dir == 't') - (dir == 'b');
    • }
    • return coords;
    • }
    • makeMove
    • =(c,s)=>
    • [...s].reduce((r,d)=>[r[0]+(d=='r')-(d=='l'),r[1]+(d=='t')-(d=='b')],c)

1 Million entries is not that large so we can still solve it naively.

Code
Diff
  • module ExampleSolution
    
    let findUniqueNumber arr =
        arr
        |> Seq.countBy id
        |> Seq.find (fun (_, count) -> count = 1)
        |> fst
    • module ExampleSolution
    • let findUniqueNumber array =
    • () // your code goes here
    • let findUniqueNumber arr =
    • arr
    • |> Seq.countBy id
    • |> Seq.find (fun (_, count) -> count = 1)
    • |> fst

in one line

Code
Diff
  • def repair(cur: list, pre: list):cur[[i.count("?") > 0 for i in cur].index(True)] = pre[[pre.index(i) for i in pre if [(o, i) for o, i in enumerate([*i]) if (o, i) in list(filter(lambda x: x[1] != '', enumerate(map(lambda x: x if x != "?" else "", [*cur[[i.count("?") > 0 for i in cur].index(True)]]))))] == list(filter(lambda x: x[1] != '', enumerate(map(lambda x: x if x != "?" else "", [*cur[[i.count("?") > 0 for i in cur].index(True)]])))) and len(i) == len(cur[[i.count("?") > 0 for i in cur].index(True)])][0]];return cur
    • def repair(cur: list, pre: list):
    • broken_index = [i.count("?") > 0 for i in cur].index(True)
    • known_part = list(filter(lambda x: x[1] != '', enumerate(map(lambda x: x if x != "?" else "", [*cur[broken_index]]))))
    • matching_pre_index = [pre.index(i) for i in pre if [(o, i) for o, i in enumerate([*i]) if (o, i) in known_part] == known_part and len(i) == len(cur[broken_index])][0]
    • cur[broken_index] = pre[matching_pre_index]
    • return cur
    • def repair(cur: list, pre: list):cur[[i.count("?") > 0 for i in cur].index(True)] = pre[[pre.index(i) for i in pre if [(o, i) for o, i in enumerate([*i]) if (o, i) in list(filter(lambda x: x[1] != '', enumerate(map(lambda x: x if x != "?" else "", [*cur[[i.count("?") > 0 for i in cur].index(True)]]))))] == list(filter(lambda x: x[1] != '', enumerate(map(lambda x: x if x != "?" else "", [*cur[[i.count("?") > 0 for i in cur].index(True)]])))) and len(i) == len(cur[[i.count("?") > 0 for i in cur].index(True)])][0]];return cur