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
  • hello_world=lambda world: "No "*(1-world) + "Hello "*world + "World" + " baby"*world
    • def hello_world(world): return "Hello World baby" if world else 'No World'
    • hello_world=lambda world: "No "*(1-world) + "Hello "*world + "World" + " baby"*world
Code
Diff
  • using System;
    
    public static class Kata
    {
        public static int SameCase(char a, char b)
        {
            var aZ = a <= 'Z';
            var bZ = b <= 'Z';
            var aIsLetter = a >= 'A' && a <= 'z' && (aZ || a >= 'a');
            if (aIsLetter != (b >= 'A' && b <= 'z' && (bZ || b >= 'a'))) return -1;
            return (!aIsLetter || aZ == bZ) ? 1 : 0;
        }
    }
    • using System;
    • public static class Kata
    • {
    • public static int SameCase(char a, char b)
    • {
    • if (!char.IsLetter(a) && !char.IsLetter(b))
    • return 1;
    • if (!char.IsLetter(a) || !char.IsLetter(b))
    • return -1;
    • return (char.IsUpper(a) == char.IsUpper(b)) ? 1 : 0;
    • var aZ = a <= 'Z';
    • var bZ = b <= 'Z';
    • var aIsLetter = a >= 'A' && a <= 'z' && (aZ || a >= 'a');
    • if (aIsLetter != (b >= 'A' && b <= 'z' && (bZ || b >= 'a'))) return -1;
    • return (!aIsLetter || aZ == bZ) ? 1 : 0;
    • }
    • }
Code
Diff
  • const tab = (f, a, b, h) => {
      return Array.from(
        {
          length: Math.ceil((b - a) / h) + 1
        },
        (v, i) => f(a + (i * h))).reduce((a, c) => a += c, 0
      )
    }
    
    • const tab = (f, a, b, h) => Array.from({length:Math.ceil((b-a)/h)+1}, (v,i) => f(a+(i*h))).reduce((a,c) => a+=c,0)
    • const tab = (f, a, b, h) => {
    • return Array.from(
    • {
    • length: Math.ceil((b - a) / h) + 1
    • },
    • (v, i) => f(a + (i * h))).reduce((a, c) => a += c, 0
    • )
    • }
Code
Diff
  • from pprint import pprint 
    
    result = 222
    pprint(f"Hello world+ {result}!")
    
    
    • from pprint import pprint
    • result = 222
    • print(f"Hello world {result}!")
    • pprint(f"Hello world+ {result}!")

Sets have a non-transitive relation, similarly to rock paper scissors. I used this property to implement the game win conditions.

Code
Diff
  • def dumbRockPaperScissors(player1, player2):
        Rock = {"Paper"}
        Paper = {"Scissors"}
        Scissors = {"Rock"}
        if player1 in eval(player2):
            return "Player 1 wins"
        elif player2 in eval(player1):
            return "Player 2 wins"
        else:
            return "Draw"
     
    
    • function dumbRockPaperScissors(player1, player2) {
    • if(player1 == "Rock" && player2 == "Paper"){
    • return "Player 2 wins";
    • }
    • else if(player1 == "Rock" && player2 == "Scissors" ){
    • return "Player 1 wins";
    • }
    • else if(player1 == "Scissors" && player2 == "Paper"){
    • return "Player 1 wins";
    • }
    • else if(player1 == "Scissors" && player2 == "Rock"){
    • return "Player 2 wins";
    • }
    • else if(player1 == "Paper" && player2 == "Scissors"){
    • return "Player 2 wins";
    • }
    • else if(player1 == "Paper" && player2 == "Rock"){
    • return "Player 1 wins";
    • }
    • else if(player1 == "Paper" && player2 == "Paper"){
    • return "Draw";
    • }
    • else if(player1 == "Rock" && player2 == "Rock"){
    • return "Draw";
    • }
    • else if(player1 == "Scissors" && player2 == "Scissors"){
    • return "Draw";
    • }
    • }
    • def dumbRockPaperScissors(player1, player2):
    • Rock = {"Paper"}
    • Paper = {"Scissors"}
    • Scissors = {"Rock"}
    • if player1 in eval(player2):
    • return "Player 1 wins"
    • elif player2 in eval(player1):
    • return "Player 2 wins"
    • else:
    • return "Draw"
Test Cases
Diff
  • import codewars_test as test
    from solution import dumbRockPaperScissors
    
    @test.describe("dumbRockPaperScissors")
    def fixed_tests():
        @test.it('Basic Test Cases')
        def basic_test_cases():
            test.assert_equals(dumbRockPaperScissors('Rock', 'Rock'),'Draw')
            test.assert_equals(dumbRockPaperScissors('Rock', 'Paper'),'Player 2 wins')
            test.assert_equals(dumbRockPaperScissors('Paper', 'Rock'),'Player 1 wins')
            test.assert_equals(dumbRockPaperScissors('Paper', 'Paper'),'Draw')
            test.assert_equals(dumbRockPaperScissors('Rock', 'Scissors'),'Player 1 wins')
            test.assert_equals(dumbRockPaperScissors('Paper', 'Scissors'),'Player 2 wins')
            test.assert_equals(dumbRockPaperScissors('Scissors', 'Rock'),'Player 2 wins')
            test.assert_equals(dumbRockPaperScissors('Scissors', 'Paper'),'Player 1 wins')
            test.assert_equals(dumbRockPaperScissors('Scissors', 'Scissors'),'Draw')
    
    • // Since Node 10, we're using Mocha.
    • // You can use `chai` for assertions.
    • const chai = require("chai");
    • const assert = chai.assert;
    • // Uncomment the following line to disable truncating failure messages for deep equals, do:
    • // chai.config.truncateThreshold = 0;
    • // Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
    • // Uncomment the following to use the old assertions:
    • // const Test = require("@codewars/test-compat");
    • import codewars_test as test
    • from solution import dumbRockPaperScissors
    • describe('dumbRockPaperScissors', function() {
    • it('returns "Draw" for Rock vs Rock', function() {
    • assert.strictEqual(dumbRockPaperScissors('Rock', 'Rock'), 'Draw');
    • });
    • it('returns "Draw" for Paper vs Paper', function() {
    • assert.strictEqual(dumbRockPaperScissors('Paper', 'Paper'), 'Draw');
    • });
    • it('returns "Draw" for Scissors vs Scissors', function() {
    • assert.strictEqual(dumbRockPaperScissors('Scissors', 'Scissors'), 'Draw');
    • });
    • it('returns "Player 1 wins" for Rock vs Scissors', function() {
    • assert.strictEqual(dumbRockPaperScissors('Rock', 'Scissors'), 'Player 1 wins');
    • });
    • it('returns "Player 1 wins" for Scissors vs Paper', function() {
    • assert.strictEqual(dumbRockPaperScissors('Scissors', 'Paper'), 'Player 1 wins');
    • });
    • it('returns "Player 1 wins" for Paper vs Rock', function() {
    • assert.strictEqual(dumbRockPaperScissors('Paper', 'Rock'), 'Player 1 wins');
    • });
    • it('returns "Player 2 wins" for Scissors vs Rock', function() {
    • assert.strictEqual(dumbRockPaperScissors('Scissors', 'Rock'), 'Player 2 wins');
    • });
    • it('returns "Player 2 wins" for Paper vs Scissors', function() {
    • assert.strictEqual(dumbRockPaperScissors('Paper', 'Scissors'), 'Player 2 wins');
    • });
    • it('returns "Player 2 wins" for Rock vs Paper', function() {
    • assert.strictEqual(dumbRockPaperScissors('Rock', 'Paper'), 'Player 2 wins');
    • });
    • });
    • @test.describe("dumbRockPaperScissors")
    • def fixed_tests():
    • @test.it('Basic Test Cases')
    • def basic_test_cases():
    • test.assert_equals(dumbRockPaperScissors('Rock', 'Rock'),'Draw')
    • test.assert_equals(dumbRockPaperScissors('Rock', 'Paper'),'Player 2 wins')
    • test.assert_equals(dumbRockPaperScissors('Paper', 'Rock'),'Player 1 wins')
    • test.assert_equals(dumbRockPaperScissors('Paper', 'Paper'),'Draw')
    • test.assert_equals(dumbRockPaperScissors('Rock', 'Scissors'),'Player 1 wins')
    • test.assert_equals(dumbRockPaperScissors('Paper', 'Scissors'),'Player 2 wins')
    • test.assert_equals(dumbRockPaperScissors('Scissors', 'Rock'),'Player 2 wins')
    • test.assert_equals(dumbRockPaperScissors('Scissors', 'Paper'),'Player 1 wins')
    • test.assert_equals(dumbRockPaperScissors('Scissors', 'Scissors'),'Draw')
Code
Diff
  • const firstNonRepeatingCharacter = (str) => {
      console.log("haha");
        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;
                }
            }
            if (!seenDuplicate) {
                return str[i];
            }
        }
        return null; // return null if no unique character is found
    };
    • const firstNonRepeatingCharacter = (str) => {
    • console.log("haha");
    • 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;
    • }
    • }
    • if (!seenDuplicate) {
    • return str[i];
    • }
    • }
    • return null; // return null if no unique character is found
    • };
Code
Diff
  • import java.util.Arrays;
    
    public class MaxNumber {
        public static long print(long number) {
          String numberStr = Long.toString(number);
          char[] digits = numberStr.toCharArray();
          Arrays.sort(digits);
          for (int i = 0; i < digits.length / 2; i++) {
                char temp = digits[i];
                digits[i] = digits[digits.length - i - 1];
                digits[digits.length - i - 1] = temp;
            }
          String maxNumberStr = new String(digits);
           number =  Long.parseLong(maxNumberStr);
            return number;
        }
    }
    • import java.util.Arrays;
    • public class MaxNumber {
    • public static long print(long number) {
    • return number
    • String numberStr = Long.toString(number);
    • char[] digits = numberStr.toCharArray();
    • Arrays.sort(digits);
    • for (int i = 0; i < digits.length / 2; i++) {
    • char temp = digits[i];
    • digits[i] = digits[digits.length - i - 1];
    • digits[digits.length - i - 1] = temp;
    • }
    • String maxNumberStr = new String(digits);
    • number = Long.parseLong(maxNumberStr);
    • return number;
    • }
    • }