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.
import requests def odd_even(n): url = 'https://www.codewars.com' if n % (requests.get(url).status_code // 100) == 0: return 0 return 1
- import requests
- def odd_even(n):
def invert_sign(s):if s == "odd":return "e" + "v" + "e" + "n"else:return "o" + "d" + "d"if n < 0:return odd_even(n - 2 * (-abs(-n)))n = int(n ** (81 ** 0.25))sign = "even"x = 0.while x < n:sign = invert_sign(sign)x += 3.14159265358 // 3n = pow(n, 1)return sign == "odd"- url = 'https://www.codewars.com'
- if n % (requests.get(url).status_code // 100) == 0:
- return 0
- return 1
import codewars_test as test from solution import odd_even @test.describe("Example") def test_group(): @test.it("test case 1: Testing Even Numbers") def test_case(): for n in range(-10, 10, 2): test.assert_equals(odd_even(n), 0) @test.it("test case 2: Testing Odd Numbers") def test_case(): for n in range(-9, 10, 2): test.assert_equals(odd_even(n), 1)
- import codewars_test as test
- from solution import odd_even
- @test.describe("Example")
- def test_group():
- @test.it("test case 1: Testing Even Numbers")
- def test_case():
for n in range(-100, 101, 2):- for n in range(-10, 10, 2):
- test.assert_equals(odd_even(n), 0)
- @test.it("test case 2: Testing Odd Numbers")
- def test_case():
for n in range(-101, 101, 2):- for n in range(-9, 10, 2):
- test.assert_equals(odd_even(n), 1)
Using the reduce methods
module AddNumbers where add_arr x = sum x
pub fn add_arr(arr: &[i16]) -> i16{arr.iter().sum()}- module AddNumbers where
- add_arr x = sum x
module AddNumbersSpec where import Test.Hspec import AddNumbers spec :: Spec spec = do describe "add_arr" $ do it "1..9" $ do (add_arr [1..9]) `shouldBe` (45) it "1..3,-4,5..9" $ do (add_arr [1,2,3,-4,5,6,7,8,9]) `shouldBe` (37)
#[cfg(test)]mod tests {use super::*;- module AddNumbersSpec where
#[test]fn test_add_arr() {assert_eq!(add_arr(&[1,2,3,4,5,6,7,8,9]), 45);assert_eq!(add_arr(&[1,2,3,-4,5,6,7,8,9]), 37);}}- import Test.Hspec
- import AddNumbers
- spec :: Spec
- spec = do
- describe "add_arr" $ do
- it "1..9" $ do
- (add_arr [1..9]) `shouldBe` (45)
- it "1..3,-4,5..9" $ do
- (add_arr [1,2,3,-4,5,6,7,8,9]) `shouldBe` (37)
def return_hundred(n): return n
def n(n=100):def lol():def lol():def lol():nonlocal nif n:lol=lambda:100return lol()else:return lol()return lolreturn lolreturn lol()()()- def return_hundred(n):
- return n
Test.assert_equals(return_hundred(n),100)
Test.assert_equals(n(),100)- Test.assert_equals(return_hundred(n),100)
def is_anagram(str1, str2): return sorted(str1) == sorted(str2)
function isAnagram(str1, str2) {if (str1.length !== str2.length) {return false;}const frequency = {};for (let i = 0; i < str1.length; i++) {const char = str1[i];if (frequency[char]) {frequency[char]++;} else {frequency[char] = 1;}}for (let i = 0; i < str2.length; i++) {const char = str2[i];if (!frequency[char]) {return false;} else {frequency[char]--;}}return true;}- def is_anagram(str1, str2):
- return sorted(str1) == sorted(str2)
import codewars_test as test from solution import is_anagram @test.describe("Example") def test_group(): @test.it("test case 1: is Anagram True") def test_case(): true_samples = ( (('listen', 'silent'), True), (('race', 'care'), True), (('night', 'thing'), True),) for s, e in true_samples: test.assert_equals(is_anagram(s[0], s[1]), e) @test.it("test case 2: is Anagram False") def test_case(): false_samples = ( (('abcd', 'abc'), False), (('anagram', 'nag a ram'), False), (('night', 'things'), False),) for s, e in false_samples: test.assert_equals(is_anagram(s[0], s[1]), e)
const chai = require("chai");const assert = chai.assert;const Test = require("@codewars/test-compat");- import codewars_test as test
- from solution import is_anagram
describe('isAnagram', () => {it('should return true for anagrams', () => {assert.strictEqual(isAnagram('listen', 'silent'), true);assert.strictEqual(isAnagram('race', 'care'), true);});it('should return false for non-anagrams', () => {assert.strictEqual(isAnagram('night', 'things'), false);assert.strictEqual(isAnagram('hello', 'world'), false);});it('should return false if input strings have different lengths', () => {assert.strictEqual(isAnagram('abc', 'abcd'), false);assert.strictEqual(isAnagram('abcd', 'abc'), false);assert.strictEqual(isAnagram('anagram', 'nag a ram'), false);});});- @test.describe("Example")
- def test_group():
- @test.it("test case 1: is Anagram True")
- def test_case():
- true_samples = (
- (('listen', 'silent'), True),
- (('race', 'care'), True),
- (('night', 'thing'), True),)
- for s, e in true_samples:
- test.assert_equals(is_anagram(s[0], s[1]), e)
- @test.it("test case 2: is Anagram False")
- def test_case():
- false_samples = (
- (('abcd', 'abc'), False),
- (('anagram', 'nag a ram'), False),
- (('night', 'things'), False),)
- for s, e in false_samples:
- test.assert_equals(is_anagram(s[0], s[1]), e)