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.util.List; import java.util.ArrayList; class Mastermind{ static String evaluate(String secret, String guess) { String[] secretColors = parseColors(secret); String[] guessColors = parseColors(guess); int correct = countCorrect(secretColors, guessColors); int misplaced = countMisplaced(secretColors, guessColors); return "[" + correct + "," + misplaced + "]"; } private static String[] parseColors(String colors) { return colors.replace("[", "").replace("]", "").split(","); } private static int countCorrect(String[] secretColors, String[] guessColors) { int correct = 0; for(int i = 0; i < secretColors.length; i++) { if (secretColors[i].equals(guessColors[i])) { correct++; } } return correct; } private static int countMisplaced(String[] secretColors, String[] guessColors) { int misplaced = 0; List<String> secretsLeftovers = new ArrayList<>(); List<String> guessLeftovers = new ArrayList<>(); for(int i = 0; i < secretColors.length; i++) { if (secretColors[i].equals(guessColors[i])) { continue; } else { secretsLeftovers.add(secretColors[i]); guessLeftovers.add(guessColors[i]); } } for (String color : secretsLeftovers) { if (guessLeftovers.contains(color)) { misplaced++; } } return misplaced; } }
- import java.util.List;
- import java.util.ArrayList;
- class Mastermind{
- static String evaluate(String secret, String guess) {
secret = secret.replace("[", "").replace("]", "");guess = guess.replace("[", "").replace("]", "");List<String> secretColors = List.of(secret.split(",")); //["red", "green"]List<String> guessColors = List.of(guess.split(","));- String[] secretColors = parseColors(secret);
- String[] guessColors = parseColors(guess);
- int correct = countCorrect(secretColors, guessColors);
- int misplaced = countMisplaced(secretColors, guessColors);
- return "[" + correct + "," + misplaced + "]";
- }
- private static String[] parseColors(String colors) {
- return colors.replace("[", "").replace("]", "").split(",");
- }
- private static int countCorrect(String[] secretColors, String[] guessColors) {
- int correct = 0;
for(int i = 0; i < secretColors.size(); i++) {if (secretColors.get(i).equals(guessColors.get(i))) {correct++;}- for(int i = 0; i < secretColors.length; i++) {
- if (secretColors[i].equals(guessColors[i])) {
- correct++;
- }
- }
- return correct;
- }
- private static int countMisplaced(String[] secretColors, String[] guessColors) {
- int misplaced = 0;
- List<String> secretsLeftovers = new ArrayList<>();
- List<String> guessLeftovers = new ArrayList<>();
return "[" + correct + ",0]";- for(int i = 0; i < secretColors.length; i++) {
- if (secretColors[i].equals(guessColors[i])) {
- continue;
- } else {
- secretsLeftovers.add(secretColors[i]);
- guessLeftovers.add(guessColors[i]);
- }
- }
- for (String color : secretsLeftovers) {
- if (guessLeftovers.contains(color)) {
- misplaced++;
- }
- }
- return misplaced;
- }
- }
}
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; // TODO: Replace examples and use TDD by writing your own tests class SolutionTest { @Test void one_peg_zero_correct() { assertEquals(Mastermind.evaluate("[blue]", "[red]"), "[0,0]"); } @Test void one_peg_one_correct() { assertEquals(Mastermind.evaluate("[red]", "[red]"), "[1,0]"); } @Test void two_pegs_one_correct() { assertEquals(Mastermind.evaluate("[red,blue]", "[red,green]"), "[1,0]"); } @Test void two_pegs_two_correct() { assertEquals(Mastermind.evaluate("[red,blue]", "[red,blue]"), "[2,0]"); } @Test void three_pegs_two_correct() { assertEquals(Mastermind.evaluate("[red,blue,green]", "[red,blue,yellow]"), "[2,0]"); } @Test void three_pegs_one_correct_one_misplaced() { assertEquals(Mastermind.evaluate("[red,blue,green]", "[red,yellow,blue]"), "[1,1]"); } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- // TODO: Replace examples and use TDD by writing your own tests
- class SolutionTest {
- @Test
- void one_peg_zero_correct() {
- assertEquals(Mastermind.evaluate("[blue]", "[red]"), "[0,0]");
- }
- @Test
- void one_peg_one_correct() {
- assertEquals(Mastermind.evaluate("[red]", "[red]"), "[1,0]");
- }
- @Test
- void two_pegs_one_correct() {
- assertEquals(Mastermind.evaluate("[red,blue]", "[red,green]"), "[1,0]");
- }
- @Test
- void two_pegs_two_correct() {
- assertEquals(Mastermind.evaluate("[red,blue]", "[red,blue]"), "[2,0]");
- }
- @Test
- void three_pegs_two_correct() {
- assertEquals(Mastermind.evaluate("[red,blue,green]", "[red,blue,yellow]"), "[2,0]");
- }
- @Test
- void three_pegs_one_correct_one_misplaced() {
- assertEquals(Mastermind.evaluate("[red,blue,green]", "[red,yellow,blue]"), "[1,1]");
- }
- }
import static java.util.stream.IntStream.rangeClosed; import java.util.List; interface FizzBuzz { static List<String> evaluate(int input) { return rangeClosed(1, input).mapToObj(FizzBuzz::determineFizzbuzz).toList(); } private static String determineFizzbuzz(int n) { switch (n%15){ case 0: return "FizzBuzz"; case 5,10: return "Buzz"; case 3,6,9,12: return "Fizz"; default: return Integer.toString(n); } } }
- import static java.util.stream.IntStream.rangeClosed;
- import java.util.List;
- interface FizzBuzz {
- static List<String> evaluate(int input) {
- return rangeClosed(1, input).mapToObj(FizzBuzz::determineFizzbuzz).toList();
- }
- private static String determineFizzbuzz(int n) {
if (n % 15 == 0) return "FizzBuzz";if (n % 3 == 0) return "Fizz";if (n % 5 == 0) return "Buzz";return Integer.toString(n);- switch (n%15){
- case 0:
- return "FizzBuzz";
- case 5,10:
- return "Buzz";
- case 3,6,9,12:
- return "Fizz";
- default:
- return Integer.toString(n);
- }
- }
- }
import java.util.HashMap; import java.util.Map; class ReservationSystem { private static final int MAX_CAPACITY = 12; private final Map<String, Integer> availabilityByDate = new HashMap<>(); private final Map<String, Integer> reservations = new HashMap<>(); public boolean request(String date, String name, String phone, int size) { int available = availabilityByDate.getOrDefault(date, MAX_CAPACITY); if (size < 1 || available < size) { return false; } reservations.put(date+name+phone, size); availabilityByDate.put(date, available - size); return true; } public void cancel(String date, String name, String phone) { var size = reservations.remove(date+ name+phone); if (size != null) { availabilityByDate.computeIfPresent(date, (d, c) -> c + size); } } }
- import java.util.HashMap;
- import java.util.Map;
- class ReservationSystem {
- private static final int MAX_CAPACITY = 12;
- private final Map<String, Integer> availabilityByDate = new HashMap<>();
private final Map<Reservation, Integer> reservations = new HashMap<>();- private final Map<String, Integer> reservations = new HashMap<>();
- public boolean request(String date, String name, String phone, int size) {
- int available = availabilityByDate.getOrDefault(date, MAX_CAPACITY);
- if (size < 1 || available < size) {
- return false;
- }
reservations.put(new Reservation(date, name, phone), size);- reservations.put(date+name+phone, size);
- availabilityByDate.put(date, available - size);
- return true;
- }
- public void cancel(String date, String name, String phone) {
var size = reservations.remove(new Reservation(date, name, phone));- var size = reservations.remove(date+ name+phone);
- if (size != null) {
- availabilityByDate.computeIfPresent(date, (d, c) -> c + size);
- }
- }
private record Reservation(String date, String name, String phone) {}- }
// 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"); describe("evenOrOdd",function() { it("Basic tests",function() { assert.strictEqual((2).evenOrOdd(), 'Even') assert.strictEqual((3).evenOrOdd(), 'Odd') assert.strictEqual((9.2).evenOrOdd(), 'Not an integer') assert.strictEqual((9).evenOrOdd(), 'Odd') }); })
- // 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");
- describe("evenOrOdd",function() {
- it("Basic tests",function() {
//assert.strictEqual(evenOrOdd(2), 'Even')//assert.strictEqual(evenOrOdd(3), 'Odd')//assert.strictEqual(evenOrOdd('adc'), 'Not an integer')//assert.strictEqual(evenOrOdd(9.2), 'Not an integer')//assert.strictEqual(evenOrOdd('4'), 'Even')//assert.strictEqual(evenOrOdd('9'), 'Odd')- assert.strictEqual((2).evenOrOdd(), 'Even')
- assert.strictEqual((3).evenOrOdd(), 'Odd')
- assert.strictEqual((9.2).evenOrOdd(), 'Not an integer')
- assert.strictEqual((9).evenOrOdd(), 'Odd')
- });
- })