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 java.text.ParseException; import java.util.ArrayList; import java.util.Arrays; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; public class Kata{ public static String[] replaceLetter(String str, int n) { ArrayList<String> arr = new ArrayList<>(); StringBuilder strFinal = new StringBuilder(str); for (int i = 0; i < str.length(); i++) { int nextIndex = (i + n) % str.length() ; if (str.charAt(i) != ' ' && str.charAt(nextIndex) != ' ') { nextIndex = (i + n) % str.length(); strFinal.replace(i, i + 1, String.valueOf(str.charAt(nextIndex))); arr.add(strFinal.toString()); strFinal.replace(0, str.length(), str); } } System.out.println(arr.toString()); String[] array = arr.toArray(new String[arr.size()]); return array; } }
- import java.text.ParseException;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Random;
- import java.util.concurrent.ThreadLocalRandom;
- public class Kata{
- public static String[] replaceLetter(String str, int n) {
- ArrayList<String> arr = new ArrayList<>();
- StringBuilder strFinal = new StringBuilder(str);
- for (int i = 0; i < str.length(); i++) {
int nextIndex = 0;- int nextIndex = (i + n) % str.length() ;
- if (str.charAt(i) != ' ' && str.charAt(nextIndex) != ' ') {
- nextIndex = (i + n) % str.length();
- strFinal.replace(i, i + 1, String.valueOf(str.charAt(nextIndex)));
- arr.add(strFinal.toString());
- strFinal.replace(0, str.length(), str);
- }
- }
- System.out.println(arr.toString());
- String[] array = arr.toArray(new String[arr.size()]);
- return array;
- }
- }
import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import java.util.Random; // TODO: Replace examples and use TDD by writing your own tests class SolutionTest { @Test @Tag("BasicTest") void BasicTest() { String [] reverseLeterHello = {"lello", "hollo", "hehlo", "heleo", "helll"}; String [] reverseLeterBye = {"eye", "bbe", "byy"}; String [] reverseLeterCodewars = {"oello codewars", "hdllo codewars", "heelo codewars", "helwo codewars", "hella codewars", "hello sodewars", "hello chdewars", "hello coeewars", "hello codlwars", "hello codelars", "hello codewors", "hello codewarc"}; assertArrayEquals(reverseLeterHello, Kata.replaceLetter("hello", 3)); assertArrayEquals(reverseLeterBye, Kata.replaceLetter("bye", 2)); assertArrayEquals(reverseLeterCodewars, Kata.replaceLetter("hello codewars", 7)); } @Test @Tag("UnitTest") void parseExceptionFecha() { assertThrows(NullPointerException.class, () -> { int nRandom = new Random().nextInt(15)+1; Kata.replaceLetter(null, nRandom); }); } }
- import static org.junit.jupiter.api.Assertions.*;
- import org.junit.jupiter.api.DisplayName;
- import org.junit.jupiter.api.RepeatedTest;
- import org.junit.jupiter.api.Tag;
- import org.junit.jupiter.api.Test;
- import java.util.Random;
- // TODO: Replace examples and use TDD by writing your own tests
- class SolutionTest {
- @Test
- @Tag("BasicTest")
- void BasicTest() {
String [] reverseLeterHola = {"oola", "hlla", "hoaa", "holh"};String [] reverseLeterAdios = {"ddios", "aiios", "adoos", "adiss", "adioa"};assertArrayEquals(reverseLeterHola, Kata.replaceLetter("hola",1));assertArrayEquals(reverseLeterAdios, Kata.replaceLetter("adios",1));- String [] reverseLeterHello = {"lello", "hollo", "hehlo", "heleo", "helll"};
- String [] reverseLeterBye = {"eye", "bbe", "byy"};
- String [] reverseLeterCodewars = {"oello codewars", "hdllo codewars", "heelo codewars", "helwo codewars", "hella codewars", "hello sodewars", "hello chdewars", "hello coeewars", "hello codlwars", "hello codelars", "hello codewors", "hello codewarc"};
- assertArrayEquals(reverseLeterHello, Kata.replaceLetter("hello", 3));
- assertArrayEquals(reverseLeterBye, Kata.replaceLetter("bye", 2));
- assertArrayEquals(reverseLeterCodewars, Kata.replaceLetter("hello codewars", 7));
- }
- @Test
- @Tag("UnitTest")
- void parseExceptionFecha() {
- assertThrows(NullPointerException.class, () -> {
- int nRandom = new Random().nextInt(15)+1;
- Kata.replaceLetter(null, nRandom);
- });
- }
- }
import java.util.*; public class Kata { public static String keyAlphabet(String str) { String[] arr = str.split(" "); List<String> listKey = new ArrayList<String>(); PriorityQueue<String> listValue = new PriorityQueue<>(); TreeMap<String, String> alphabet = new TreeMap<>(); for (String item : arr) { if (item.length() == 1 && item.charAt(0) >= 'a' && item.charAt(0) <= 'z') { listKey.add(item); } else { listValue.add(item); } } List<String> values = new ArrayList<>(listValue); for (String value : values) { for (String s : listKey) { if (value.contains(s)) { if (alphabet.containsKey(s)) { alphabet.put(s, alphabet.get(s) + "," + value); } else { alphabet.put(s, value); } } } } StringBuilder result = new StringBuilder(); for (Map.Entry<String, String> m : alphabet.entrySet()) { result.append(m.getKey()).append(":").append(m.getValue()).append(" "); } return result.toString().trim(); } }
- import java.util.*;
- public class Kata {
- public static String keyAlphabet(String str) {
- String[] arr = str.split(" ");
- List<String> listKey = new ArrayList<String>();
- PriorityQueue<String> listValue = new PriorityQueue<>();
- TreeMap<String, String> alphabet = new TreeMap<>();
- for (String item : arr) {
- if (item.length() == 1 && item.charAt(0) >= 'a' && item.charAt(0) <= 'z') {
- listKey.add(item);
- } else {
- listValue.add(item);
- }
- }
- List<String> values = new ArrayList<>(listValue);
- for (String value : values) {
- for (String s : listKey) {
- if (value.contains(s)) {
- if (alphabet.containsKey(s)) {
- alphabet.put(s, alphabet.get(s) + "," + value);
- } else {
- alphabet.put(s, value);
- }
- }
- }
- }
return "";- StringBuilder result = new StringBuilder();
- for (Map.Entry<String, String> m : alphabet.entrySet()) {
- result.append(m.getKey()).append(":").append(m.getValue()).append(" ");
- }
- return result.toString().trim();
- }
- }
import org.junit.Test; import static org.junit.Assert.assertEquals; import org.junit.runners.JUnit4; public class SolutionTest { @Test public void sampleTests() { assertEquals("a:11a1 b:222b22 c:3c33", Kata.keyAlphabet("a b c 11a1 222b22 3c33")); assertEquals("a:11a1,222a33 b:222b22 c:3c33", Kata.keyAlphabet("222a33 a b c 11a1 222b22 3c33 5")); assertEquals("a:11a1,12a1,13a1 c:33c3 d:2d2", Kata.keyAlphabet("a d c x 11a1 2d2 33c3 13a1 12a1")); assertEquals("", Kata.keyAlphabet("")); assertEquals("a:11a1 b:2b2 c:33c3", Kata.keyAlphabet("a b c d 11a1 33c3 2b2")); assertEquals("a:11a1 b:2b2 c:33c3", Kata.keyAlphabet("a b c 11a1 33c3 2b2 d44")); } }
- import org.junit.Test;
- import static org.junit.Assert.assertEquals;
- import org.junit.runners.JUnit4;
- public class SolutionTest {
- @Test
- public void sampleTests() {
//assertEquals("a:11a1 b:222b22 c:3c33", Kata.keyAlphabet("a b c 11a1 222b22 3c33"));//assertEquals("a:11a1,222a33 b:222b22 c:3c33", Kata.keyAlphabet("222a33 a b c 11a1 222b22 3c33 5"));//assertEquals("a:11a1,12a1,13a1 c:33c3 d:2d2", Kata.keyAlphabet("a d c x 11a1 2d2 33c3 13a1 12a1"));//assertEquals("", Kata.keyAlphabet(""));// assertEquals("a:11a1 b:2b2 c:33c3", Kata.keyAlphabet("a b c d 11a1 33c3 2b2"));//assertEquals("a:11a1 b:2b2 c:33c3", Kata.keyAlphabet("a b c 11a1 33c3 2b2 d44"));- assertEquals("a:11a1 b:222b22 c:3c33", Kata.keyAlphabet("a b c 11a1 222b22 3c33"));
- assertEquals("a:11a1,222a33 b:222b22 c:3c33", Kata.keyAlphabet("222a33 a b c 11a1 222b22 3c33 5"));
- assertEquals("a:11a1,12a1,13a1 c:33c3 d:2d2", Kata.keyAlphabet("a d c x 11a1 2d2 33c3 13a1 12a1"));
- assertEquals("", Kata.keyAlphabet(""));
- assertEquals("a:11a1 b:2b2 c:33c3", Kata.keyAlphabet("a b c d 11a1 33c3 2b2"));
- assertEquals("a:11a1 b:2b2 c:33c3", Kata.keyAlphabet("a b c 11a1 33c3 2b2 d44"));
- }
- }
const isAnagram = (s1, s2) => s1.length === s2.length && Object.values([...s1].reduce((o, k, i) => (k in o ? ++o[k] : o[k] = 1, s2[i] in o ? --o[s2[i]] : o[s2[i]] = -1, o), {})).every(v => !v);
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;}- const isAnagram = (s1, s2) => s1.length === s2.length && Object.values([...s1].reduce((o, k, i) => (k in o ? ++o[k] : o[k] = 1, s2[i] in o ? --o[s2[i]] : o[s2[i]] = -1, o), {})).every(v => !v);
function capitalize(sentence) { return sentence.split(' ').map(w => w[0].toUpperCase() + w.slice(1)).join(' '); }
- function capitalize(sentence) {
let words = sentence.split(' ');const length = words.length;for (let i = 0; i < length; ++i) {words[i] = words[i][0].toUpperCase() + words[i].substr(1)}return words.join(' ');}console.log(capitalize("i am a javascript programmer"));- return sentence.split(' ').map(w => w[0].toUpperCase() + w.slice(1)).join(' ');
- }
def decompose(num): return [int(i) for i in ''.join(map(str, num))] def greatest(num): return int(''.join(sorted(''.join(map(str, decompose(num))), reverse=True)))
- def decompose(num):
- return [int(i) for i in ''.join(map(str, num))]
- def greatest(num):
return int(''.join(sorted([str(y) for x in [[int(z) for z in str(n)] for n in num] for y in x], reverse=True)))- return int(''.join(sorted(''.join(map(str, decompose(num))), reverse=True)))
def binary_to_integer(b): # I didn't know that you don't need prefix '0b' for convertion, so I wrote it like this return int(f'0b{b}', 2)
- def binary_to_integer(b):
return sum([x[0] for x in list(zip([pow(2,i) for i in range(len(b))], reversed(b))) if x[1] == '1'])- # I didn't know that you don't need prefix '0b' for convertion, so I wrote it like this
- return int(f'0b{b}', 2)
def knight_move3d(pos=(0, 0, 0)) -> bool: if pos == (0, 0, 0): return True return [*sorted(map(abs, pos))] == [0, 1, 2]
def knight_move3d(position=(0, 0, 0)) -> bool:if position == (0, 0, 0):- def knight_move3d(pos=(0, 0, 0)) -> bool:
- if pos == (0, 0, 0):
- return True
_sum: int = 0mul: int = 1for i in position:if i > 2 or -2 > i:return False_sum += abs(i)mul = mul * ireturn _sum == 3 and mul == 0- return [*sorted(map(abs, pos))] == [0, 1, 2]
def pyramid_of_x(n): if n < 2: return 'Not enough building blocks!' return '\n'.join(['*' * i for i in range(1, n + 1)])
- def pyramid_of_x(n):
- if n < 2:
- return 'Not enough building blocks!'
rows = ['*' * i for i in range(1, n + 1)]return '\n'.join(rows)- return '\n'.join(['*' * i for i in range(1, n + 1)])
import java.util.Arrays; public class HighLow{ public static int[] printLargestAndSmallest(int[] nums){ return nums == null || nums.length==0 ? null : new int[]{Arrays.stream(nums).min() .getAsInt(),Arrays.stream(nums).max().getAsInt()}; } }
- import java.util.Arrays;
- public class HighLow{
- public static int[] printLargestAndSmallest(int[] nums){
int low[] = nums;int high[] = nums;int lowest = nums[0];int highest = nums[0];int count = 0;for(int i = 0; i < nums.length;i+=2){int num1 = nums[i];int num2 = nums[i+1];if(num1<num2){low[count] = num1;high[count] = num2;count++;}else{low[count] = num2;high[count] = num1;count++;}lowest = low[0];highest = high[0];for(int j = 1; j < low.length; j++){if(low[j] < lowest){lowest = low[j];}}for(int j = 1; j < high.length; j++){if(high[j] > highest){highest = high[j];}}}int[] finalHighLow = new int[2];finalHighLow[0] = lowest;finalHighLow[1] = highest;return finalHighLow;- return nums == null || nums.length==0 ? null : new int[]{Arrays.stream(nums).min()
- .getAsInt(),Arrays.stream(nums).max().getAsInt()};
- }
- }
def foo(lst, i, n): done = i > n fb = not (i % 3 or i % 5) f = not i % 3 b = not i % 5 match (done, fb, f, b): case (1, _, _, _): return lst case (_, 1, _, _): return foo(lst + ["fizzbuzz"], i + 1, n) case (_, _, 1, _): return foo(lst + ["fizz"], i + 1, n) case (_, _, _, 1): return foo(lst + ["buzz"], i + 1, n) case _: return foo(lst + [str(i)], i + 1, n) def fizzbuzz(n): return foo([],1,n)
def rec(acc,i,n):done=i>nmatch done:case True:return acc- def foo(lst, i, n):
- done = i > n
- fb = not (i % 3 or i % 5)
- f = not i % 3
- b = not i % 5
- match (done, fb, f, b):
- case (1, _, _, _):
- return lst
- case (_, 1, _, _):
- return foo(lst + ["fizzbuzz"], i + 1, n)
- case (_, _, 1, _):
- return foo(lst + ["fizz"], i + 1, n)
- case (_, _, _, 1):
- return foo(lst + ["buzz"], i + 1, n)
- case _:
fb=not (i%3 or i%5)f=not i%3b=not i%5match fb:case True:return rec(acc+["fizzbuzz"],i+1,n)case _:match f:case True:return rec(acc+["fizz"],i+1,n)case _:match b:case True:return rec(acc+["buzz"],i+1,n)case _:return rec(acc+[str(i)],i+1,n)- return foo(lst + [str(i)], i + 1, n)
- def fizzbuzz(n):
return rec([],1,n)# def fizzbuzz(n):# acc=[]# i=1# while i<=n:# if not (i%3 or i%5):# acc.append("fizzbuzz")# elif not i%3:# acc.append("fizz")# elif not i%5:# acc.append("buzz")# else:# acc.append(str(i))# i+=1# return acc- return foo([],1,n)
import codewars_test as test from solution import fizzbuzz @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(1 + 1, 2) test.assert_equals(fizzbuzz(0), []) test.assert_equals(fizzbuzz(1), ['1']) test.assert_equals(fizzbuzz(11), ['1', '2', 'fizz', '4', 'buzz', 'fizz', '7', '8', 'fizz', 'buzz', '11']) test.assert_equals(fizzbuzz(7), ['1', '2', 'fizz', '4', 'buzz', 'fizz', '7'])
- import codewars_test as test
# TODO Write testsimport solution # or from solution import example- from solution import fizzbuzz
# test.assert_equals(actual, expected, [optional] message)- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- test.assert_equals(1 + 1, 2)
- test.assert_equals(fizzbuzz(0), [])
- test.assert_equals(fizzbuzz(1), ['1'])
- test.assert_equals(fizzbuzz(11), ['1', '2', 'fizz', '4', 'buzz', 'fizz', '7', '8', 'fizz', 'buzz', '11'])
- test.assert_equals(fizzbuzz(7), ['1', '2', 'fizz', '4', 'buzz', 'fizz', '7'])