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.
alvaro..buvs.gonzalo.sl18 days ago
Driving Test Evaluator
import java.util.HashMap; import java.util.List; import java.util.Map; public class DrivingTestEvaluator{ static Map<String, String> rules = new HashMap<>(); static int knockoutFoul; static int mildFoul; public static boolean evaluate(String road, String exam) { return false; } public static void comprobateSpeedLimit(String rule, List<String> actions) { String[] parts = rule.substring(2).split("_"); int speedLimit = Integer.parseInt(parts[0]); int duration = Integer.parseInt(parts[1]); int overLimitCounter = 0; boolean minorCounted = false; for (int i = 0; i < Math.min(duration, actions.size()); i++) { String act = actions.get(i); int speed = extractSpeed(act); if (speed > speedLimit + 10) { knockoutFoul++; return; } if (speed > speedLimit) { overLimitCounter++; } else { overLimitCounter = 0; } if (overLimitCounter >= 3 && !minorCounted) { mildFoul++; minorCounted = true; } } for (int i = 0; i < duration && !actions.isEmpty(); i++) { actions.remove(0); } } public static void comprobateStop(String rule, List<String> actions) { int cars = rule.length() > 4 ? Integer.parseInt(rule.substring(4)) : 0; int requiredStop = 3 + (2 * cars); int stopCount = 0; for (int i = 0; i < actions.size(); i++) { if (extractSpeed(actions.get(i)) == 0) { stopCount++; } else { i = actions.size(); } } if (stopCount == 0) { knockoutFoul++; } else if (stopCount < requiredStop) { if (stopCount >= 2 * cars) mildFoul++; else knockoutFoul++; } for (int i = 0; i < stopCount && !actions.isEmpty(); i++) { actions.remove(0); } } public static void comprobateYield(String rule, List<String> actions) { int cars = rule.length() > 5 ? Integer.parseInt(rule.substring(5)) : 0; int requiredStop = 2 * cars; int stopCount = 0; for (int i = 0; i < actions.size(); i++) { if (extractSpeed(actions.get(i)) == 0) { stopCount++; } else { i = actions.size(); } } if (cars == 0) { if (stopCount >= 2) { knockoutFoul++; } } else { if (stopCount < requiredStop) { knockoutFoul++; } else if (stopCount < requiredStop + 3) { mildFoul++; } } for (int i = 0; i < stopCount && !actions.isEmpty(); i++) { actions.remove(0); } } public static void comprobateTurn(String rule, List<String> actions) { String requiredDirection = rule.equals("TURNR") ? ">" : "<"; boolean turned = false; int index = -1; for (int i = 0; i < actions.size(); i++) { if (actions.get(i).endsWith(requiredDirection)) { turned = true; index = i; i = actions.size(); } } if (!turned) { mildFoul++; } else { for (int j = 0; j <= index && !actions.isEmpty(); j++) { actions.remove(0); } } } public static void comprobateRedLight(String rule, List<String> actions) { int duration = Integer.parseInt(rule.substring(1)); boolean failed = false; for (int i = 0; i < duration && i < actions.size(); i++) { if (extractSpeed(actions.get(i)) != 0) { failed = true; } } if (failed) { knockoutFoul++; } for (int i = 0; i < duration && !actions.isEmpty(); i++) { actions.remove(0); } } public static int extractSpeed(String action) { if (action.endsWith("<") || action.endsWith(">")) { return Integer.parseInt(action.substring(0, action.length() - 1)); } return Integer.parseInt(action); } }
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- public class DrivingTestEvaluator{
public static boolean evaluate(String road, String exam){//your code heree- static Map<String, String> rules = new HashMap<>();
- static int knockoutFoul;
- static int mildFoul;
- public static boolean evaluate(String road, String exam) {
- return false;
- }
- public static void comprobateSpeedLimit(String rule, List<String> actions) {
- String[] parts = rule.substring(2).split("_");
- int speedLimit = Integer.parseInt(parts[0]);
- int duration = Integer.parseInt(parts[1]);
- int overLimitCounter = 0;
- boolean minorCounted = false;
- for (int i = 0; i < Math.min(duration, actions.size()); i++) {
- String act = actions.get(i);
- int speed = extractSpeed(act);
- if (speed > speedLimit + 10) {
- knockoutFoul++;
- return;
- }
- if (speed > speedLimit) {
- overLimitCounter++;
- } else {
- overLimitCounter = 0;
- }
- if (overLimitCounter >= 3 && !minorCounted) {
- mildFoul++;
- minorCounted = true;
- }
- }
- for (int i = 0; i < duration && !actions.isEmpty(); i++) {
- actions.remove(0);
- }
- }
- public static void comprobateStop(String rule, List<String> actions) {
- int cars = rule.length() > 4 ? Integer.parseInt(rule.substring(4)) : 0;
- int requiredStop = 3 + (2 * cars);
- int stopCount = 0;
- for (int i = 0; i < actions.size(); i++) {
- if (extractSpeed(actions.get(i)) == 0) {
- stopCount++;
- } else {
- i = actions.size();
- }
- }
- if (stopCount == 0) {
- knockoutFoul++;
- } else if (stopCount < requiredStop) {
- if (stopCount >= 2 * cars) mildFoul++;
- else knockoutFoul++;
- }
- for (int i = 0; i < stopCount && !actions.isEmpty(); i++) {
- actions.remove(0);
- }
- }
- public static void comprobateYield(String rule, List<String> actions) {
- int cars = rule.length() > 5 ? Integer.parseInt(rule.substring(5)) : 0;
- int requiredStop = 2 * cars;
- int stopCount = 0;
- for (int i = 0; i < actions.size(); i++) {
- if (extractSpeed(actions.get(i)) == 0) {
- stopCount++;
- } else {
- i = actions.size();
- }
- }
- if (cars == 0) {
- if (stopCount >= 2) {
- knockoutFoul++;
- }
- } else {
- if (stopCount < requiredStop) {
- knockoutFoul++;
- } else if (stopCount < requiredStop + 3) {
- mildFoul++;
- }
- }
- for (int i = 0; i < stopCount && !actions.isEmpty(); i++) {
- actions.remove(0);
- }
- }
- public static void comprobateTurn(String rule, List<String> actions) {
- String requiredDirection = rule.equals("TURNR") ? ">" : "<";
- boolean turned = false;
- int index = -1;
- for (int i = 0; i < actions.size(); i++) {
- if (actions.get(i).endsWith(requiredDirection)) {
- turned = true;
- index = i;
- i = actions.size();
- }
- }
- if (!turned) {
- mildFoul++;
- } else {
- for (int j = 0; j <= index && !actions.isEmpty(); j++) {
- actions.remove(0);
- }
- }
- }
- public static void comprobateRedLight(String rule, List<String> actions) {
- int duration = Integer.parseInt(rule.substring(1));
- boolean failed = false;
- for (int i = 0; i < duration && i < actions.size(); i++) {
- if (extractSpeed(actions.get(i)) != 0) {
- failed = true;
- }
- }
- if (failed) {
- knockoutFoul++;
- }
- for (int i = 0; i < duration && !actions.isEmpty(); i++) {
- actions.remove(0);
- }
- }
return true;- public static int extractSpeed(String action) {
- if (action.endsWith("<") || action.endsWith(">")) {
- return Integer.parseInt(action.substring(0, action.length() - 1));
- }
- return Integer.parseInt(action);
- }
- }
Kachevs.coulrulner119 days ago
Make It Greater Than 2
Original seems to do unnecessary computation before ultimately returning True
gabriel.gsvs.antonio.rg19 days ago
Cross Math
import static org.junit.jupiter.api.Assertions.assertArrayEquals; import java.util.Arrays; import java.util.Random; import org.junit.jupiter.api.Test; class SolutionTest { void TestRandomA() { for(int z = 0; z < 100; z++) { String[][] board = generatePlusMinusMultiDiv(); String[][] end = generatePlusMinusMultiDiv(); for(int i = 0; i < end.length; i++) { end[i] = board[i].clone(); } for(int i = 0; i < board.length; i++) { for(int k = 0; k < board[i].length; k++) { end[i][k] = board[i][k]; } } board = incognitaCreator(board); System.out.println(Arrays.deepToString(board)); System.out.println(Arrays.deepToString(end)); assertArrayEquals(end, CrossMath.solve(board)); } } void TestRandomB(){ for(int i = 0; i < 100; i++){ String[][] expected = generateSol(); String[][] input = incognitaCreator(expected); assertArrayEquals(expected,input); } } public static String[][] generateSol(){ int num1 = new Random().nextInt(1,100); int num2 = new Random().nextInt(1,100); int corners = num1 * num2; String[][] solution = new String[5][5]; for(int y = 0; y < solution.length; y++) for(int x = 0; x < solution[y].length; x++) solution[y][x] = " "; for(int i = 0; i < solution.length; i +=2) { solution[i][solution.length-2] = "="; solution[solution.length-2][i] = "="; } if (new Random().nextBoolean()) { solution[0][0] = String.valueOf(num1); solution[solution.length-1][solution.length-1]= String.valueOf(num2); solution[0][solution.length-1] = String.valueOf(num1*num2); solution[solution.length-1][0] = String.valueOf(num1*num2); } else { solution[0][solution.length-1] = String.valueOf(num1); solution[solution.length-1][0] = String.valueOf(num2); solution[0][0] = String.valueOf(num1*num2); solution[solution.length-1][solution.length-1] = String.valueOf(num1*num2); } if (Integer.parseInt(solution[0][0]) > Integer.parseInt(solution[0][solution.length-1])) { solution[0][1] = "/"; solution[0][2] = String.valueOf(Integer.parseInt(solution[0][0])/Integer.parseInt(solution[0][solution.length-1])); } else { solution[0][1] = "*"; solution[0][2] = String.valueOf(Integer.parseInt(solution[0][solution.length-1])/Integer.parseInt(solution[0][0])); } if (Integer.parseInt(solution[solution.length-1][0]) > Integer.parseInt(solution[solution.length-1][solution.length-1])) { solution[solution.length-1][1] = "/"; solution[solution.length-1][2] = String.valueOf(Integer.parseInt(solution[solution.length-1][0])/Integer.parseInt(solution[solution.length-1][solution.length-1])); } else { solution[solution.length-1][1] = "*"; solution[solution.length-1][2] = String.valueOf(Integer.parseInt(solution[solution.length-1][solution.length-1])/Integer.parseInt(solution[solution.length-1][0])); } if (Integer.parseInt(solution[0][0]) > Integer.parseInt(solution[solution.length-1][0])) { solution[1][0] = "-"; solution[2][0] = String.valueOf(Integer.parseInt(solution[0][0])-Integer.parseInt(solution[solution.length-1][0])); } else { solution[1][0] = "+"; solution[2][0] = String.valueOf(Integer.parseInt(solution[solution.length-1][0])-Integer.parseInt(solution[0][0])); } if (Integer.parseInt(solution[0][solution.length-1]) > Integer.parseInt(solution[solution.length-1][solution.length-1])) { solution[1][solution.length-1] = "-"; solution[2][solution.length-1] = String.valueOf(Integer.parseInt(solution[0][solution.length-1])-Integer.parseInt(solution[solution.length-1][solution.length-1])); } else { solution[1][solution.length-1] = "+"; solution[2][solution.length-1] = String.valueOf(Integer.parseInt(solution[solution.length-1][solution.length-1])-Integer.parseInt(solution[0][solution.length-1])); } if (Integer.parseInt(solution[0][2]) > Integer.parseInt(solution[solution.length-1][2])) { solution[1][2] = "-"; solution[2][2] = String.valueOf(Integer.parseInt(solution[0][2])-Integer.parseInt(solution[solution.length-1][2])); } else { solution[1][2] = "+"; solution[2][2] = String.valueOf(Integer.parseInt(solution[solution.length-1][2])-Integer.parseInt(solution[0][2])); } if (Integer.parseInt(solution[2][0]) > Integer.parseInt(solution[2][solution.length-1])) { solution[2][1] = "-"; } else { solution[2][1] = "+"; } return solution; } public static String[][] generatePlusMinusMultiDiv() { Random r = new Random(); String[][] moss = new String[5][5]; if(r.nextInt(2) == 1) { int mult = r.nextInt(5)+1; int base = r.nextInt(5)+5; int num = base*mult; if(base > mult) { moss[1][2] = "+"; moss[2][1] = "+"; }else { moss[1][2] = "-"; moss[2][1] = "-"; } moss[0][0] = String.valueOf(base); moss[0][1] = "+"; moss[0][2] = String.valueOf(num-base); moss[0][3] = "="; moss[0][4] = String.valueOf(num); moss[1][0] = "*"; moss[1][1] = " "; moss[1][3] = " "; moss[1][4] = "/"; moss[2][0] = String.valueOf(mult); moss[2][2] = String.valueOf(Math.abs(base-mult)); moss[2][3] = "="; moss[2][4] = String.valueOf(base); moss[3][0] = "="; moss[3][1] = " "; moss[3][2] = "="; moss[3][3] = " "; moss[3][4] = "="; moss[4][0] = String.valueOf(num); moss[4][1] = "-"; moss[4][2] = String.valueOf(num-mult); moss[4][3] = "="; moss[4][4] = String.valueOf(mult); }else { int mult = r.nextInt(9)+1; int base = r.nextInt(9)+1; int num = base*mult; if(base < mult) { moss[1][2] = "-"; moss[2][1] = "+"; }else { moss[1][2] = "+"; moss[2][1] = "-"; } moss[0][0] = String.valueOf(num); moss[0][1] = "-"; moss[0][2] = String.valueOf(num-base); moss[0][3] = "="; moss[0][4] = String.valueOf(base); moss[1][0] = "/"; moss[1][1] = " "; moss[1][3] = " "; moss[1][4] = "*"; moss[2][0] = String.valueOf(base); moss[2][2] = String.valueOf(Math.abs(base-mult)); moss[2][3] = "="; moss[2][4] = String.valueOf(mult); moss[3][0] = "="; moss[3][1] = " "; moss[3][2] = "="; moss[3][3] = " "; moss[3][4] = "="; moss[4][0] = String.valueOf(mult); moss[4][1] = "+"; moss[4][2] = String.valueOf(num-mult); moss[4][3] = "="; moss[4][4] = String.valueOf(num); } return moss; } public static String[][] incognitaCreator(String[][] moss) { String[] arr = {"A","B","C"}; Random r = new Random(); for(String a : arr) { moss[r.nextInt(3)*2][r.nextInt(3)*2] = a; } return moss; } }
- import static org.junit.jupiter.api.Assertions.assertArrayEquals;
- import java.util.Arrays;
- import java.util.Random;
- import org.junit.jupiter.api.Test;
- class SolutionTest {
- @Test
- void TestRandomA() {
- for(int z = 0; z < 100; z++) {
- String[][] board = generatePlusMinusMultiDiv();
- String[][] end = generatePlusMinusMultiDiv();
- for(int i = 0; i < end.length; i++) {
- end[i] = board[i].clone();
- }
- for(int i = 0; i < board.length; i++) {
- for(int k = 0; k < board[i].length; k++) {
- end[i][k] = board[i][k];
- }
- }
- board = incognitaCreator(board);
- System.out.println(Arrays.deepToString(board));
- System.out.println(Arrays.deepToString(end));
- assertArrayEquals(end, CrossMath.solve(board));
- }
- }
- @Test
- void TestRandomB(){
- for(int i = 0; i < 100; i++){
- String[][] expected = generateSol();
- String[][] input = incognitaCreator(expected);
- assertArrayEquals(expected,input);
- }
- }
- public static String[][] generateSol(){
- int num1 = new Random().nextInt(1,100);
- int num2 = new Random().nextInt(1,100);
- int corners = num1 * num2;
- String[][] solution = new String[5][5];
- for(int y = 0; y < solution.length; y++)
- for(int x = 0; x < solution[y].length; x++)
- solution[y][x] = " ";
- for(int i = 0; i < solution.length; i +=2) {
- solution[i][solution.length-2] = "=";
- solution[solution.length-2][i] = "=";
- }
- if (new Random().nextBoolean()) {
- solution[0][0] = String.valueOf(num1);
- solution[solution.length-1][solution.length-1]= String.valueOf(num2);
- solution[0][solution.length-1] = String.valueOf(num1*num2);
- solution[solution.length-1][0] = String.valueOf(num1*num2);
- } else {
- solution[0][solution.length-1] = String.valueOf(num1);
- solution[solution.length-1][0] = String.valueOf(num2);
- solution[0][0] = String.valueOf(num1*num2);
- solution[solution.length-1][solution.length-1] = String.valueOf(num1*num2);
- }
- if (Integer.parseInt(solution[0][0]) > Integer.parseInt(solution[0][solution.length-1])) {
- solution[0][1] = "/";
- solution[0][2] = String.valueOf(Integer.parseInt(solution[0][0])/Integer.parseInt(solution[0][solution.length-1]));
- } else {
- solution[0][1] = "*";
- solution[0][2] = String.valueOf(Integer.parseInt(solution[0][solution.length-1])/Integer.parseInt(solution[0][0]));
- }
- if (Integer.parseInt(solution[solution.length-1][0]) > Integer.parseInt(solution[solution.length-1][solution.length-1])) {
- solution[solution.length-1][1] = "/";
- solution[solution.length-1][2] = String.valueOf(Integer.parseInt(solution[solution.length-1][0])/Integer.parseInt(solution[solution.length-1][solution.length-1]));
- } else {
- solution[solution.length-1][1] = "*";
- solution[solution.length-1][2] = String.valueOf(Integer.parseInt(solution[solution.length-1][solution.length-1])/Integer.parseInt(solution[solution.length-1][0]));
- }
- if (Integer.parseInt(solution[0][0]) > Integer.parseInt(solution[solution.length-1][0])) {
- solution[1][0] = "-";
- solution[2][0] = String.valueOf(Integer.parseInt(solution[0][0])-Integer.parseInt(solution[solution.length-1][0]));
- } else {
- solution[1][0] = "+";
- solution[2][0] = String.valueOf(Integer.parseInt(solution[solution.length-1][0])-Integer.parseInt(solution[0][0]));
- }
- if (Integer.parseInt(solution[0][solution.length-1]) > Integer.parseInt(solution[solution.length-1][solution.length-1])) {
- solution[1][solution.length-1] = "-";
- solution[2][solution.length-1] = String.valueOf(Integer.parseInt(solution[0][solution.length-1])-Integer.parseInt(solution[solution.length-1][solution.length-1]));
- } else {
- solution[1][solution.length-1] = "+";
- solution[2][solution.length-1] = String.valueOf(Integer.parseInt(solution[solution.length-1][solution.length-1])-Integer.parseInt(solution[0][solution.length-1]));
- }
- if (Integer.parseInt(solution[0][2]) > Integer.parseInt(solution[solution.length-1][2])) {
- solution[1][2] = "-";
- solution[2][2] = String.valueOf(Integer.parseInt(solution[0][2])-Integer.parseInt(solution[solution.length-1][2]));
- } else {
- solution[1][2] = "+";
- solution[2][2] = String.valueOf(Integer.parseInt(solution[solution.length-1][2])-Integer.parseInt(solution[0][2]));
- }
- if (Integer.parseInt(solution[2][0]) > Integer.parseInt(solution[2][solution.length-1])) {
- solution[2][1] = "-";
- } else {
- solution[2][1] = "+";
- }
- return solution;
- }
- public static String[][] generatePlusMinusMultiDiv() {
- Random r = new Random();
- String[][] moss = new String[5][5];
- if(r.nextInt(2) == 1) {
- int mult = r.nextInt(5)+1;
- int base = r.nextInt(5)+5;
- int num = base*mult;
- if(base > mult) {
- moss[1][2] = "+";
- moss[2][1] = "+";
- }else {
- moss[1][2] = "-";
- moss[2][1] = "-";
- }
- moss[0][0] = String.valueOf(base);
- moss[0][1] = "+";
- moss[0][2] = String.valueOf(num-base);
- moss[0][3] = "=";
- moss[0][4] = String.valueOf(num);
- moss[1][0] = "*";
- moss[1][1] = " ";
- moss[1][3] = " ";
- moss[1][4] = "/";
- moss[2][0] = String.valueOf(mult);
- moss[2][2] = String.valueOf(Math.abs(base-mult));
- moss[2][3] = "=";
- moss[2][4] = String.valueOf(base);
- moss[3][0] = "=";
- moss[3][1] = " ";
- moss[3][2] = "=";
- moss[3][3] = " ";
- moss[3][4] = "=";
- moss[4][0] = String.valueOf(num);
- moss[4][1] = "-";
- moss[4][2] = String.valueOf(num-mult);
- moss[4][3] = "=";
- moss[4][4] = String.valueOf(mult);
- }else {
- int mult = r.nextInt(9)+1;
- int base = r.nextInt(9)+1;
- int num = base*mult;
- if(base < mult) {
- moss[1][2] = "-";
- moss[2][1] = "+";
- }else {
- moss[1][2] = "+";
- moss[2][1] = "-";
- }
- moss[0][0] = String.valueOf(num);
- moss[0][1] = "-";
- moss[0][2] = String.valueOf(num-base);
- moss[0][3] = "=";
- moss[0][4] = String.valueOf(base);
- moss[1][0] = "/";
- moss[1][1] = " ";
- moss[1][3] = " ";
- moss[1][4] = "*";
- moss[2][0] = String.valueOf(base);
- moss[2][2] = String.valueOf(Math.abs(base-mult));
- moss[2][3] = "=";
- moss[2][4] = String.valueOf(mult);
- moss[3][0] = "=";
- moss[3][1] = " ";
- moss[3][2] = "=";
- moss[3][3] = " ";
- moss[3][4] = "=";
- moss[4][0] = String.valueOf(mult);
- moss[4][1] = "+";
- moss[4][2] = String.valueOf(num-mult);
- moss[4][3] = "=";
- moss[4][4] = String.valueOf(num);
- }
- return moss;
- }
- public static String[][] incognitaCreator(String[][] moss) {
- String[] arr = {"A","B","C"};
- Random r = new Random();
- for(String a : arr) {
- moss[r.nextInt(3)*2][r.nextInt(3)*2] = a;
- }
- return moss;
- }
- }