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::BTreeSet;
    
    fn first_non_repeating_character(s: &str) -> Option<char> {
        let mut seen = Vec::new();
        let mut repeated = BTreeSet::new();
        for c in s.chars() {
            if repeated.contains(&c) {
                continue;
            }
            if let Some(idx) = seen.iter().position(|&ch| ch == c) {
                seen.remove(idx);
                repeated.insert(c);
            } else {
                seen.push(c);
            }
        }
        seen.first().copied()
        
    }
    • const firstNonRepeatingCharacter = (str) => {
    • for (let i = 0; i < str.length; i++) {
    • let seenDuplicate = false;
    • for (let j = 0; j < str.length; j++) {
    • if (str[i] === str[j] && i !== j) {
    • seenDuplicate = true;
    • break;
    • }
    • use std::collections::BTreeSet;
    • fn first_non_repeating_character(s: &str) -> Option<char> {
    • let mut seen = Vec::new();
    • let mut repeated = BTreeSet::new();
    • for c in s.chars() {
    • if repeated.contains(&c) {
    • continue;
    • }
    • if (!seenDuplicate) {
    • return str[i];
    • if let Some(idx) = seen.iter().position(|&ch| ch == c) {
    • seen.remove(idx);
    • repeated.insert(c);
    • } else {
    • seen.push(c);
    • }
    • }
    • return null; // return null if no unique character is found
    • };
    • seen.first().copied()
    • }
Code
Diff
  • def multiply(a,b):
        return a*b
    
    result = multiply(5,10)
    print(result)
    
    • from math import prod
    • def multiply(a,b):
    • return a*b
    • def multiply(a, b):
    • ints = (a, b)
    • return prod(ints)
    • result = multiply(5, 10)
    • result = multiply(5,10)
    • print(result)
Code
Diff
  • function sum(a,b) {
      return +a + +b; // Now works for strings
    }
    • function sum(a,b) {
    • return a+b; // wrong returning
    • return +a + +b; // Now works for strings
    • }
Code
Diff
  • const nums = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
    const digitToText = nums.at.bind(nums) ?? 'idk'
    • const nums = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
    • function digitToText(digit) {
    • return nums[digit]
    • }
    • const digitToText = nums.at.bind(nums) ?? 'idk'
Code
Diff
  • const cinema_auditorium = (spisok2D,ryad)=> {
      var output = (spisok2D[ryad].reduce((summaStulev,stulya ) => summaStulev + stulya, 0));
      console.log(output);
      var stulya = spisok2D[ryad].reduce((summaStulev,stulya ) => summaStulev + stulya, 0);
      return stulya;
    }
    • const cinema_auditorium = (spisok2D,ryad)=> {
    • console.log(spisok2D,ryad)
    • return 3
    • var output = (spisok2D[ryad].reduce((summaStulev,stulya ) => summaStulev + stulya, 0));
    • console.log(output);
    • var stulya = spisok2D[ryad].reduce((summaStulev,stulya ) => summaStulev + stulya, 0);
    • return stulya;
    • }

Moves the actions into a nested object, where the first level is Player1's action and the second layer Player 2's action.

This makes the templating easier.

also added an "Invalid action!" error if either player makes an invalid move.

Code
Diff
  • function rps(player1, player2) {
      const actions = {
        rock: {
          paper: 2,
          scissors: 1,
          rock: 0,
        },
        paper: {
          paper: 0,
          scissors: 2,
          rock: 1,
        },
        scissors: {
          paper: 1,
          scissors: 0,
          rock: 2,
        },
      };
    
      const result = actions?.[player1]?.[player2];
    
      if (result === 0) return "Draw!";
      if (!result) throw "Invalid action!";
      return `Player ${result} won!`;
    }
    • function rps(player1, player2) {
    • return player1 == player2 ? 'Draw!' :
    • player1 == 'rock' && player2 == 'scissors' ||
    • player1 == 'scissors' && player2 == 'paper' ||
    • player1 == 'paper' && player2 == 'rock' ? 'Player 1 won!' : 'Player 2 won!';
    • }
    • const actions = {
    • rock: {
    • paper: 2,
    • scissors: 1,
    • rock: 0,
    • },
    • paper: {
    • paper: 0,
    • scissors: 2,
    • rock: 1,
    • },
    • scissors: {
    • paper: 1,
    • scissors: 0,
    • rock: 2,
    • },
    • };
    • const result = actions?.[player1]?.[player2];
    • if (result === 0) return "Draw!";
    • if (!result) throw "Invalid action!";
    • return `Player ${result} won!`;
    • }
Code
Diff
  • use std::ops::Add;
    
    fn add<T: Add<Output = T>>(a: T, b: T) -> T {
        a.add(b)
    }
    
    • // write a add function that doesn't use the plus symbol
    • function add(a, b){
    • return a + b;
    • }
    • use std::ops::Add;
    • // Make sure to view the test cases to see how this test fails
    • fn add<T: Add<Output = T>>(a: T, b: T) -> T {
    • a.add(b)
    • }

.

Code
Diff
  • const numMinusSeven = function(num) {
        return num - 7;
    }
    • const numMinusSeven = function(num) {
    • let youGoodBro = [];
    • while (num > 0) {
    • num -= 7;
    • youGoodBro.push(num);
    • }
    • return youGoodBro.length;
    • return num - 7;
    • }
Code
Diff
  • def sum(arr):
        if len(arr) == 1:
            return arr[0]
        else:
            return list(map(lambda x: x + x, arr))[-1]
    • def sum(arr):
    • result = 0
    • for i in arr:
    • result += i
    • return result
    • if len(arr) == 1:
    • return arr[0]
    • else:
    • return list(map(lambda x: x + x, arr))[-1]