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 missing_number(nums: &[u32]) -> u32 {
        (0..=nums.len() as u32).find(|n| !nums.contains(&n)).unwrap()
    }
    • class Solution {
    • public:
    • int missingNumber(vector<int>& nums) {
    • }
    • };
    • fn missing_number(nums: &[u32]) -> u32 {
    • (0..=nums.len() as u32).find(|n| !nums.contains(&n)).unwrap()
    • }

Remove the character 'a' or 'A' from strings.

Updated test cases to be... possible.

Code
Diff
  • #include <algorithm>
    std::string remove_a (std::string s)
    {
        s.erase(std::remove_if(s.begin(), s.end(), [](char c){return c == 'a' || c == 'A';}), s.end());
        return s;
    }
    • #include <bits/stdc++.h>
    • #include <algorithm>
    • std::string remove_a (std::string s)
    • {
    • s.erase(std::remove_if(s.begin(), s.end(), [](char c){return c == 'a' || c == 'A';}), s.end());
    • return s;
    • }
Strings
Code
Diff
  • isUnique=s=>[...new Set(s)].join``==s
    • isUnique=s=>new Set(s).size===s.length
    • isUnique=s=>[...new Set(s)].join``==s
Code
Diff
  • fn total_fine(speed: i32, signals: &[i32]) -> u32 {
        signals.iter().map(|&signal| fine(speed, signal)).sum()
    }
    
    fn fine(speed: i32, signal: i32) -> u32 {
        match speed - signal {
            ..=9 => 0,
            10..=19 => 100,
            20..=29 => 250,
            30.. => 500
        }
    }
    • public class Kata {
    • public static int speedLimit(int speed, int[] signals) {
    • int penalty = 0;
    • for (int i = 0; i < signals.length; i++){
    • if (speed > signals[i]){
    • if (speed - signals[i] >= 30){
    • penalty += 500;
    • } else if (speed - signals[i] >= 20 && speed - signals[i] < 30){
    • penalty += 250;
    • } else if (speed - signals[i] >= 10 && speed - signals[i] < 20){
    • penalty += 100;
    • }
    • }
    • }
    • return penalty;
    • fn total_fine(speed: i32, signals: &[i32]) -> u32 {
    • signals.iter().map(|&signal| fine(speed, signal)).sum()
    • }
    • fn fine(speed: i32, signal: i32) -> u32 {
    • match speed - signal {
    • ..=9 => 0,
    • 10..=19 => 100,
    • 20..=29 => 250,
    • 30.. => 500
    • }
    • }

Optimized for speed

Code
Diff
  • fn print(mut number: u64) -> u64 {
        let mut digits = Vec::new();
        while number > 0 {
            digits.push(number % 10);
            number /= 10;
        }
        digits.sort();
        digits.into_iter().rev().fold(0, |result, digit| result * 10 + digit)
    }
    • import java.util.Arrays;
    • public class MaxNumber {
    • public static long print(long number) {
    • return number
    • fn print(mut number: u64) -> u64 {
    • let mut digits = Vec::new();
    • while number > 0 {
    • digits.push(number % 10);
    • number /= 10;
    • }
    • digits.sort();
    • digits.into_iter().rev().fold(0, |result, digit| result * 10 + digit)
    • }

js version with fixed TestCases.

Code
Diff
  • function multiplicationTable(){
      let arr = [];
      for(let i=1; i<6; i++){
        arr.push([]);
        for(let j=1; j<13; j++){
          arr[arr.length-1].push(`${i} * ${j} = ${i*j}`);
        }
      } return arr.map(e => e.join('\n')).join('\n\n');
    }
    • #include<stdio.h>
    • int main()
    • {
    • int i=1;
    • while(i<=5)
    • {
    • int j=1;
    • while(j<=12)
    • {
    • printf("%d * %d =%d \n", i,j, i*j);
    • j++;
    • function multiplicationTable(){
    • let arr = [];
    • for(let i=1; i<6; i++){
    • arr.push([]);
    • for(let j=1; j<13; j++){
    • arr[arr.length-1].push(`${i} * ${j} = ${i*j}`);
    • }
    • i++;
    • printf("\n");
    • }
    • return(0);
    • } return arr.map(e => e.join('\n')).join('\n\n');
    • }
Code
Diff
  • function formatIfNumber(value, numberOfPlaces) {
      return value===+value?+value.toFixed(numberOfPlaces):value;
    }
    • function formatIfNumber(value, numberOfPlaces) {
    • return "";
    • return value===+value?+value.toFixed(numberOfPlaces):value;
    • }

Seems like it should be worse than an atomic since there's additional overhead, but isn't notably slower.

Code
Diff
  • use std::{thread, sync::Mutex};
    
    fn count() -> u32 {
        let count = Mutex::new(0);
        thread::scope(|s| {
            for _ in 0..10 {
                s.spawn(|| {
                    for _ in 0..100 {
                        *count.lock().unwrap() += 1;
                    }
                });
            }
        });
        count.into_inner().unwrap()
    }
    • use std::{thread, sync::atomic::{AtomicU32, Ordering::Relaxed}};
    • use std::{thread, sync::Mutex};
    • fn count() -> u32 {
    • let count = AtomicU32::new(0);
    • let count = Mutex::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.lock().unwrap() += 1;
    • }
    • });
    • }
    • });
    • count.into_inner()
    • count.into_inner().unwrap()
    • }
Code
Diff
  • dumbRockPaperScissors=(a,b)=>a==b?`Draw`:`Player ${(a[0]!={'R':'P','P':'S','S':'R'}[b[0]])+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`
    • dumbRockPaperScissors=(a,b)=>a==b?`Draw`:`Player ${(a[0]!={'R':'P','P':'S','S':'R'}[b[0]])+1} wins`
Fundamentals
Code
Diff
  • def find_special(jar, special): 
        return [special] + [item for item in jar if item != special] if special and jar and special in jar else None
    • def find_special(jar, special):
    • # initial solution
    • if jar != None and jar != []:
    • for i in range(len(jar)):
    • if jar[i] == special:
    • jar.insert(0,jar.pop(i))
    • break
    • return jar
    • return None
    • def find_special(jar, special):
    • return [special] + [item for item in jar if item != special] if special and jar and special in jar else None