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.
package main import "fmt" func bubble_sort(dataset []int, amout_of_integers int){ for i := 0; i <= amout_of_integers; i++ { for j := amout_of_integers; j >= i + 1; j-- { if dataset[j] < dataset[j-1] { dataset[j], dataset[j-1] = dataset[j-1], dataset[j] } } } } func main(){ dataset := []int{5, 2, 4, 6, 1, 3}; fmt.Println(dataset) bubble_sort(dataset, 5); fmt.Println(dataset) }
- package main
- import "fmt"
func swap(dataset []int, a, b int) {var x int = dataset[a]dataset[a] = dataset[b]dataset[b] = x}- func bubble_sort(dataset []int, amout_of_integers int){
- for i := 0; i <= amout_of_integers; i++ {
- for j := amout_of_integers; j >= i + 1; j-- {
- if dataset[j] < dataset[j-1] {
swap(dataset, j, j - 1)- dataset[j], dataset[j-1] = dataset[j-1], dataset[j]
- }
- }
- }
- }
- func main(){
- dataset := []int{5, 2, 4, 6, 1, 3};
- fmt.Println(dataset)
- bubble_sort(dataset, 5);
- fmt.Println(dataset)
- }
from math import sqrt def distance2D(pA, pB): if pA == pB: return 0 (xA, yA), (xB, yB) = pA, pB return sqrt((xA - xB)**2 + (yA - yB)**2) def distance3D(pA, pB): if pA == pB: return 0 (xA, yA, zA), (xB, yB, zB) = pA, pB return sqrt((xA - xB)**2 + (yA - yB)**2 + (zA - zB) **2)
- from math import sqrt
- def distance2D(pA, pB):
- if pA == pB: return 0
xA, yA = tuple(pA); xB, yB = tuple(pB)- (xA, yA), (xB, yB) = pA, pB
- return sqrt((xA - xB)**2 + (yA - yB)**2)
- def distance3D(pA, pB):
- if pA == pB: return 0
xA, yA, zA = tuple(pA); xB, yB, zB = tuple(pB)- (xA, yA, zA), (xB, yB, zB) = pA, pB
- return sqrt((xA - xB)**2 + (yA - yB)**2 + (zA - zB) **2)
public class Dinglemouse { // Use CSS to display a pretty version of the flap display // From: https://www.codewars.com/kata/airport-arrivals-slash-departures-number-1/java public static String[] prettyPrint(final String[] lines) { String s = ""; for (int y = 0; y < lines.length; y++) { s += "<div style=\"height:23px\">"; for (int x = 0; x < lines[y].length(); x++) { s += "<span style=\"font-size:10px;color:yellow;padding:5px;border:1px solid gray;background:black\">"+lines[y].charAt(x)+"</span>"; } s += "</div>"; } System.out.println(s); return lines; } }
- public class Dinglemouse {
- // Use CSS to display a pretty version of the flap display
- // From: https://www.codewars.com/kata/airport-arrivals-slash-departures-number-1/java
- public static String[] prettyPrint(final String[] lines) {
String s = "<pre>";- String s = "";
- for (int y = 0; y < lines.length; y++) {
- s += "<div style=\"height:23px\">";
- for (int x = 0; x < lines[y].length(); x++) {
- s += "<span style=\"font-size:10px;color:yellow;padding:5px;border:1px solid gray;background:black\">"+lines[y].charAt(x)+"</span>";
- }
- s += "</div>";
- }
s+= "</pre>";- System.out.println(s);
- return lines;
- }
- }
package com.mystuff.juststuff; import java.text.*; import java.util.*; public class Palindrome { private static final SimpleDateFormat sdf = new SimpleDateFormat("MMddyyyy"); public Set<Date> countDatePalindromes(final Date startDate, final Date endDate) { final Set<Date> set = new TreeSet<>(); final GregorianCalendar startCal = new GregorianCalendar(); final GregorianCalendar endCal = new GregorianCalendar(); // If end date is before start date, flip them. startCal.setTime(startDate.before(endDate) ? startDate : endDate); endCal.setTime(startDate.after(endDate) ? startDate : endDate); for (; startCal.before(endCal) || startCal.equals(endCal); startCal.add(Calendar.DAY_OF_MONTH, 1)) { final String forward = sdf.format(startCal.getTime()); final String back = new StringBuilder(forward).reverse().toString(); if (forward.equals(back)) { set.add(startCal.getTime()); // Date string looks same both ways } } return set; } }
- package com.mystuff.juststuff;
- import java.text.*;
import java.util.Calendar;import java.util.Date;import java.util.GregorianCalendar;import java.util.TreeSet;- import java.util.*;
- public class Palindrome {
SimpleDateFormat sdf;public Palindrome() {this.sdf = new SimpleDateFormat("MMddyyyy");sdf.setLenient(false);}public TreeSet<Date> countDatePalindromes(Date startDate, Date endDate) {TreeSet<Date> palSet = new TreeSet<Date>();GregorianCalendar startCal = new GregorianCalendar();GregorianCalendar endCal = new GregorianCalendar();- private static final SimpleDateFormat sdf = new SimpleDateFormat("MMddyyyy");
/*end date is chronologically before start date. flip them.NOTE: lines 23-30 should be a pre-condition to the countDatePalindromes method,so they should be deleted.*/if (startDate.getTime() > endDate.getTime()) {startCal.setTime(endDate);endCal.setTime(startDate);}else {startCal.setTime(startDate);endCal.setTime(endDate);}String regularDate = null;String palDate = null;while ( (startCal.before(endCal)) || (startCal.equals(endCal)) ) {regularDate = sdf.format(startCal.getTime());palDate = palindromify(startCal.getTime());// a date palindrome was foundif (regularDate.equals(palDate))palSet.add(startCal.getTime());startCal.add(Calendar.DAY_OF_MONTH, 1);- public Set<Date> countDatePalindromes(final Date startDate, final Date endDate) {
- final Set<Date> set = new TreeSet<>();
- final GregorianCalendar startCal = new GregorianCalendar();
- final GregorianCalendar endCal = new GregorianCalendar();
- // If end date is before start date, flip them.
- startCal.setTime(startDate.before(endDate) ? startDate : endDate);
- endCal.setTime(startDate.after(endDate) ? startDate : endDate);
- for (; startCal.before(endCal) || startCal.equals(endCal); startCal.add(Calendar.DAY_OF_MONTH, 1)) {
- final String forward = sdf.format(startCal.getTime());
- final String back = new StringBuilder(forward).reverse().toString();
- if (forward.equals(back)) {
- set.add(startCal.getTime()); // Date string looks same both ways
- }
- }
return palSet;- return set;
- }
private String palindromify(final Date arg) {StringBuffer palBuff = new StringBuffer(8);palBuff = sdf.format(arg, palBuff, new FieldPosition(0));return palBuff.reverse().toString();}- }
package com.mystuff.juststuff; import static org.junit.Assert.assertTrue; import java.util.Date; import java.util.GregorianCalendar; import java.util.Set; import org.junit.Test; public class PalindromeTest { @Test public void testCountDatePalindromesEndDateBeforeStartDate() { GregorianCalendar startCalTest = new GregorianCalendar(2001, 11, 1); GregorianCalendar endCalTest = new GregorianCalendar(2001, 0, 31); Date startDate = new Date(startCalTest.getTimeInMillis()); Date endDate = new Date(endCalTest.getTimeInMillis()); Palindrome drome = new Palindrome(); Set<Date> palSet = drome.countDatePalindromes(startDate, endDate); assertTrue("Set size should be greater than zero", palSet.size() > 0); } @Test public void testCountDatePalindromesStartDateBeforeEndDate() { GregorianCalendar startCalTest = new GregorianCalendar(2001, 0, 1); GregorianCalendar endCalTest = new GregorianCalendar(2001, 11, 31); Date startDate = new Date(startCalTest.getTimeInMillis()); Date endDate = new Date(endCalTest.getTimeInMillis()); Palindrome drome = new Palindrome(); Set<Date> palSet = drome.countDatePalindromes(startDate, endDate); assertTrue("Set size should be greater than zero", palSet.size() > 0); } @Test public void testCountDatePalindromesStartDateEqualsEndDateNoPalindromes() { GregorianCalendar startCalTest = new GregorianCalendar(2001, 11, 31); // Nov 31, 2001 is not a palindrome date GregorianCalendar endCalTest = new GregorianCalendar(2001, 11, 31); Date startDate = new Date(startCalTest.getTimeInMillis()); Date endDate = new Date(endCalTest.getTimeInMillis()); Palindrome drome = new Palindrome(); Set<Date> palSet = drome.countDatePalindromes(startDate, endDate); assertTrue("Set size should be zero", palSet.size() == 0); } @Test public void testCountDatePalindromesStartDateEqualsEndDateOnePalindrome() { GregorianCalendar startCalTest = new GregorianCalendar(2001, 9, 2); // Oct 2, 2001 is a palindrome date GregorianCalendar endCalTest = new GregorianCalendar(2001, 9, 2); Date startDate = new Date(startCalTest.getTimeInMillis()); Date endDate = new Date(endCalTest.getTimeInMillis()); Palindrome drome = new Palindrome(); Set<Date> palSet = drome.countDatePalindromes(startDate, endDate); assertTrue("Set size should be one", palSet.size() == 1); } @Test public void testCountDatePalindromesHugeDateRange() { GregorianCalendar startCalTest = new GregorianCalendar(1900, 0, 1); GregorianCalendar endCalTest = new GregorianCalendar(2001, 11, 31); Date startDate = new Date(startCalTest.getTimeInMillis()); Date endDate = new Date(endCalTest.getTimeInMillis()); Palindrome drome = new Palindrome(); Set<Date> palSet = drome.countDatePalindromes(startDate, endDate); assertTrue("Set size should be greater than zero", palSet.size() > 0); } }
- package com.mystuff.juststuff;
- import static org.junit.Assert.assertTrue;
- import java.util.Date;
- import java.util.GregorianCalendar;
import java.util.TreeSet;- import java.util.Set;
- import org.junit.Test;
- public class PalindromeTest
- {
- @Test
- public void testCountDatePalindromesEndDateBeforeStartDate()
- {
- GregorianCalendar startCalTest = new GregorianCalendar(2001, 11, 1);
- GregorianCalendar endCalTest = new GregorianCalendar(2001, 0, 31);
- Date startDate = new Date(startCalTest.getTimeInMillis());
- Date endDate = new Date(endCalTest.getTimeInMillis());
- Palindrome drome = new Palindrome();
TreeSet<Date> palSet = drome.countDatePalindromes(startDate, endDate);- Set<Date> palSet = drome.countDatePalindromes(startDate, endDate);
- assertTrue("Set size should be greater than zero", palSet.size() > 0);
- }
- @Test
- public void testCountDatePalindromesStartDateBeforeEndDate()
- {
- GregorianCalendar startCalTest = new GregorianCalendar(2001, 0, 1);
- GregorianCalendar endCalTest = new GregorianCalendar(2001, 11, 31);
- Date startDate = new Date(startCalTest.getTimeInMillis());
- Date endDate = new Date(endCalTest.getTimeInMillis());
- Palindrome drome = new Palindrome();
TreeSet<Date> palSet = drome.countDatePalindromes(startDate, endDate);- Set<Date> palSet = drome.countDatePalindromes(startDate, endDate);
- assertTrue("Set size should be greater than zero", palSet.size() > 0);
- }
- @Test
- public void testCountDatePalindromesStartDateEqualsEndDateNoPalindromes()
- {
- GregorianCalendar startCalTest = new GregorianCalendar(2001, 11, 31); // Nov 31, 2001 is not a palindrome date
- GregorianCalendar endCalTest = new GregorianCalendar(2001, 11, 31);
- Date startDate = new Date(startCalTest.getTimeInMillis());
- Date endDate = new Date(endCalTest.getTimeInMillis());
- Palindrome drome = new Palindrome();
TreeSet<Date> palSet = drome.countDatePalindromes(startDate, endDate);- Set<Date> palSet = drome.countDatePalindromes(startDate, endDate);
- assertTrue("Set size should be zero", palSet.size() == 0);
- }
- @Test
- public void testCountDatePalindromesStartDateEqualsEndDateOnePalindrome()
- {
- GregorianCalendar startCalTest = new GregorianCalendar(2001, 9, 2); // Oct 2, 2001 is a palindrome date
- GregorianCalendar endCalTest = new GregorianCalendar(2001, 9, 2);
- Date startDate = new Date(startCalTest.getTimeInMillis());
- Date endDate = new Date(endCalTest.getTimeInMillis());
- Palindrome drome = new Palindrome();
TreeSet<Date> palSet = drome.countDatePalindromes(startDate, endDate);- Set<Date> palSet = drome.countDatePalindromes(startDate, endDate);
- assertTrue("Set size should be one", palSet.size() == 1);
- }
- @Test
- public void testCountDatePalindromesHugeDateRange()
- {
- GregorianCalendar startCalTest = new GregorianCalendar(1900, 0, 1);
- GregorianCalendar endCalTest = new GregorianCalendar(2001, 11, 31);
- Date startDate = new Date(startCalTest.getTimeInMillis());
- Date endDate = new Date(endCalTest.getTimeInMillis());
- Palindrome drome = new Palindrome();
TreeSet<Date> palSet = drome.countDatePalindromes(startDate, endDate);- Set<Date> palSet = drome.countDatePalindromes(startDate, endDate);
- assertTrue("Set size should be greater than zero", palSet.size() > 0);
- }
- }
function getFactors (n) { if (!Number.isInteger(n) || n < 1) return []; var divisors = new Set(); var step = n % 2 == 0 ? 1 : 2; for (let i = 1; i <= Math.sqrt(n); i += step) { if (n % i == 0) divisors.add(i).add(n/i) } return Array.from(divisors).sort((a,b)=>a-b) }
- function getFactors (n) {
- if (!Number.isInteger(n) || n < 1) return [];
var divisors = new Set();for (let i = 1; i <= Math.sqrt(n); i++) {- var divisors = new Set();
- var step = n % 2 == 0 ? 1 : 2;
- for (let i = 1; i <= Math.sqrt(n); i += step) {
- if (n % i == 0) divisors.add(i).add(n/i)
- }
return Array.from(divisors)- return Array.from(divisors).sort((a,b)=>a-b)
- }
describe("Solution", function(){ it("sBasic tests", function(){ Test.assertSimilar(getFactors(0), [], "Should return empty array"); Test.assertSimilar(getFactors('string'), [], "Is not a number so should return an empty array"); Test.assertSimilar(getFactors(1), [1], "'1' should be the only divisor of '1'"); Test.assertSimilar(getFactors(13), [1, 13], "'13' is a prime number, so '1, 13' should be its divisors"); Test.assertSimilar(getFactors(50), [1, 2, 5, 10, 25, 50]); Test.assertSimilar(getFactors(1234), [1, 2, 617, 1234]); Test.assertSimilar(getFactors(12345), [1, 3, 5, 15, 823, 2469, 4115, 12345]); }); });
- describe("Solution", function(){
- it("sBasic tests", function(){
- Test.assertSimilar(getFactors(0), [], "Should return empty array");
- Test.assertSimilar(getFactors('string'), [], "Is not a number so should return an empty array");
- Test.assertSimilar(getFactors(1), [1], "'1' should be the only divisor of '1'");
- Test.assertSimilar(getFactors(13), [1, 13], "'13' is a prime number, so '1, 13' should be its divisors");
Test.assertSimilar(getFactors(50), [1, 50, 2 ,25, 5, 10]);- Test.assertSimilar(getFactors(50), [1, 2, 5, 10, 25, 50]);
- Test.assertSimilar(getFactors(1234), [1, 2, 617, 1234]);
- Test.assertSimilar(getFactors(12345), [1, 3, 5, 15, 823, 2469, 4115, 12345]);
- });
- });