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

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()
    • }

Para que se devuelva el numero maximo formado de los numeros dados:

Hay que convertir el numero es un cadena de strings y juntarlos en un array, ordenarlos de menor a mayor y luego invertir el orden, devolver el array ordenado de mayor a menor pasado a formato Long.

Code
Diff
  • import java.util.Arrays;
    
    class MaxNumber {
        public static long print(long number) {
            String stringDeNumber= Long.toString(number); //convierto la variable number de Long a String
            char[] arrayNumeros = stringDeNumber.toCharArray();  // creo un array a partir del string number
            Arrays.sort(arrayNumeros); //los ordeno de menos a mayor 
            StringBuilder numerosOrdenados = new StringBuilder(new String(arrayNumeros)).reverse(); // creo una variable tipo StringBuilder para cambiar el orden y que se acomoden de mayor a menor
            return Long.parseLong(numerosOrdenados.toString()); // paso la cadena ordenada de nuevo a Long
        }
    }
    
    //La notacion Big-O es: O(n log n) Tiempo lineal-logarítmico. Ya que usa ordenamientos y reordenamientos de strings 
    • import java.util.Arrays;
    • public class MaxNumber {
    • class MaxNumber {
    • public static long print(long number) {
    • return number
    • String stringDeNumber= Long.toString(number); //convierto la variable number de Long a String
    • char[] arrayNumeros = stringDeNumber.toCharArray(); // creo un array a partir del string number
    • Arrays.sort(arrayNumeros); //los ordeno de menos a mayor
    • StringBuilder numerosOrdenados = new StringBuilder(new String(arrayNumeros)).reverse(); // creo una variable tipo StringBuilder para cambiar el orden y que se acomoden de mayor a menor
    • return Long.parseLong(numerosOrdenados.toString()); // paso la cadena ordenada de nuevo a Long
    • }
    • }
    • }
    • //La notacion Big-O es: O(n log n) Tiempo lineal-logarítmico. Ya que usa ordenamientos y reordenamientos de strings