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

Leading characters that are not letters should be ignored.

Added relevant test cases.

Code
Diff
  • module ToUpperFirst where
    
    import Data.Char (toUpper, isLetter)
    
    toUpperFirst :: String -> String
    toUpperFirst str =
      case break isLetter str of
        (xs, y:ys) -> xs ++ toUpper y : ys
        _          -> str
    • module ToUpperFirst where
    • import Data.Char (toUpper, isSpace)
    • toUpperFirst (x : xs) = if isSpace x then x : toUpperFirst xs else toUpper x : xs
    • toUpperFirst _ = ""
    • import Data.Char (toUpper, isLetter)
    • toUpperFirst :: String -> String
    • toUpperFirst str =
    • case break isLetter str of
    • (xs, y:ys) -> xs ++ toUpper y : ys
    • _ -> str

shorter code chars..

Code
Diff
  • n=s=>[...s].map(e=>("aeiou".includes(e)?"aeiou".indexOf(e)+1:e)).join``
    d=s=>[...s].map(e=>(+e&&e<6?"aeiou"[e-1]:e)).join``
    
    • n=s=>[...s].map(e=>("aeiou".includes(e)?"aeiou".indexOf(e)+1:e)).join``
    • d=s=>[...s].map(e=>("12345".includes(e)?"aeiou"[e-1]:e)).join``
    • d=s=>[...s].map(e=>(+e&&e<6?"aeiou"[e-1]:e)).join``
Code
Diff
  • class Disemvowel:
        def __init__(self, s):
            self.s = s
    
        def scalpel(self):
              return ("".join(x for x in self.s if x.lower() not in "aeiou"))
    • def disemvowel(string):
    • return ("".join(char for char in string if char.lower() not in "aeiou"))
    • class Disemvowel:
    • def __init__(self, s):
    • self.s = s
    • def scalpel(self):
    • return ("".join(x for x in self.s if x.lower() not in "aeiou"))
Code
Diff
  • class HelloWorld:
        def __init__(self, param=''):
            self.param = param        
            
        def message(self):    
            return f'Hello, {self.param.title()}!' if self.param else 'Hello, World!'
    
    • def hello_world(param=''):
    • return f'Hello, {param.title()}!' if param else 'Hello, World!'
    • class HelloWorld:
    • def __init__(self, param=''):
    • self.param = param
    • def message(self):
    • return f'Hello, {self.param.title()}!' if self.param else 'Hello, World!'

that's called "thinking outside the box"

Code
Diff
  • dumbRockPaperScissors=(a,b)=>a==b?`Draw`:`Player ${(a.slice(0,1)!={'R':'P','P':'S','S':'R'}[b.slice(0,1)])+1} wins`
    
    • dumbRockPaperScissors
    • =(a,b)=>
    • a==b?`Draw`:`Player ${(a!={'Rock':'Paper','Paper':'Scissors','Scissors':'Rock'}[b])+1} wins`
    • dumbRockPaperScissors=(a,b)=>a==b?`Draw`:`Player ${(a.slice(0,1)!={'R':'P','P':'S','S':'R'}[b.slice(0,1)])+1} wins`
Strings

Can't beat this can you? 😏

Code
Diff
  • isUnique=s=>new Set(s).size===s.length
    • isUnique = s => s.split("").filter((a,b,c) => c.indexOf(a) === b).length == s.length;
    • isUnique=s=>new Set(s).size===s.length

The simple fix. Runtime around 3 seconds for 10000 calls.

Code
Diff
  • use std::{thread, sync::atomic::{AtomicU32, Ordering::Relaxed}};
    
    fn count() -> u32 {
        let count = AtomicU32::new(0);
        thread::scope(|s| {
            for _ in 0..10 {
                s.spawn(|| {
                    for _ in 0..100 {
                        count.fetch_add(1, Relaxed);
                    }
                });
            }
        });
        count.into_inner()
    }
    • use std::{thread, sync::atomic::{AtomicU32, Ordering::Relaxed}};
    • fn count() -> u32 {
    • let count = AtomicU32::new(0);
    • thread::scope(|s| {
    • for _ in 0..10 {
    • s.spawn(|| {
    • for _ in 0..100 {
    • let current = count.load(Relaxed);
    • count.store(current + 1, Relaxed);
    • count.fetch_add(1, Relaxed);
    • }
    • });
    • }
    • });
    • count.into_inner()
    • }