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.
using System; using System.Linq; public class Kata { public static int DuplicateCount(string str) { return str .ToLower() .GroupBy(c => c) .Aggregate(0, (current, next) => current + (next.Count() > 1 ? 1 : 0)); } }
- using System;
- using System.Linq;
- public class Kata
- {
- public static int DuplicateCount(string str)
- {
var orderedLowercase = str.ToLower().OrderBy(c => c);var countDuplicates = 0;var countOccurrenciesCurrentCharacter = 1;char? previousElement = null;var firstElement = true;foreach(var currentElement in orderedLowercase){if (firstElement){firstElement = false;}else{if (currentElement == previousElement.Value){countOccurrenciesCurrentCharacter ++;if (countOccurrenciesCurrentCharacter == 2){countDuplicates ++;}}else{countOccurrenciesCurrentCharacter = 1;}}previousElement = currentElement;}return countDuplicates;- return str
- .ToLower()
- .GroupBy(c => c)
- .Aggregate(0, (current, next) => current + (next.Count() > 1 ? 1 : 0));
- }
- }
#include<stdio.h> int hello(char* name) { printf("Hello, %s!\n", name); return 0; }
- #include<stdio.h>
int main(int argc, char **argv) {printf("Hello, %s!", argv[0]);- int hello(char* name) {
- printf("Hello, %s!
- ", name);
- return 0;
- }
#include <criterion/criterion.h> int hello(char*); Test(SayHello, should_pass_all_the_tests_provided) { cr_assert_eq(hello("C"), 0); cr_assert_eq(hello("Codewars"), 0); }
- #include <criterion/criterion.h>
- int hello(char*);
- Test(SayHello, should_pass_all_the_tests_provided) {
- cr_assert_eq(hello("C"), 0);
- cr_assert_eq(hello("Codewars"), 0);
- }
using System; class Kata { public static void Main(string greeting, string language) { Console.WriteLine(greeting + ", " + language + "!"); } }
using static System.Console;class Kata{public static void Main(){var greeting = "Hello";var language = "C#";WriteLine($"{greeting}, {language}!");- using System;
- class Kata {
- public static void Main(string greeting, string language) {
- Console.WriteLine(greeting + ", " + language + "!");
- }
- }
using NUnit.Framework; using System; using System.IO; [TestFixture] public class KataTests { [Test] public void Prints_expected_output() { string language = "C#"; string greeting = "Hello"; var originalConsoleOut = Console.Out; // preserve the original stream var writer = new StringWriter(); Console.SetOut(writer); //ready to listen to console Kata.Main(greeting, language); writer.Flush(); // when you're done, make sure everything is written out var myString = writer.GetStringBuilder().ToString(); Console.SetOut(originalConsoleOut); // restore Console output Assert.AreEqual(greeting + ", " + language + "!\n" , myString); } }
- using NUnit.Framework;
- using System;
- using System.IO;
- [TestFixture]
- public class KataTests
- {
- [Test]
- public void Prints_expected_output()
- {
- string language = "C#";
- string greeting = "Hello";
- var originalConsoleOut = Console.Out; // preserve the original stream
- var writer = new StringWriter();
- Console.SetOut(writer);
- //ready to listen to console
Kata.Main();- Kata.Main(greeting, language);
- writer.Flush(); // when you're done, make sure everything is written out
- var myString = writer.GetStringBuilder().ToString();
- Console.SetOut(originalConsoleOut); // restore Console output
Assert.AreEqual("Hello, C#!" , myString);- Assert.AreEqual(greeting + ", " + language + "!
- " , myString);
- }
- }
function countCirculars(n) { let count = 0; for (let i=3;i<=n; i+=2) { if (isPrime(i) && isCirclePrime(i)) count++; } return count+1; } function isPrime(n) { if (n <= 1) return false else if (n <= 3) return true else if ((n % 2) === 0 || n % 3 === 0) return false let i = 5; while (i*i <= n) { if (n % i === 0 || n % (i + 2) === 0) return false i = i + 6 } return true } function isCirclePrime(n) { let strN = n.toString(); for (let i = 1; i<strN.length; i++) { strN = shiftString(strN); if (!isPrime(parseInt(strN))) return false } return true; } function shiftString(str) { return str.substring(1) + str.substring(0,1); }
- function countCirculars(n) {
- let count = 0;
- for (let i=3;i<=n; i+=2) {
- if (isPrime(i) && isCirclePrime(i))
- count++;
- }
- return count+1;
- }
- function isPrime(n) {
for (let i=2; i<=Math.sqrt(n); i++) {if (n%i === 0)return false;- if (n <= 1)
- return false
- else if (n <= 3)
- return true
- else if ((n % 2) === 0 || n % 3 === 0)
- return false
- let i = 5;
- while (i*i <= n) {
- if (n % i === 0 || n % (i + 2) === 0)
- return false
- i = i + 6
- }
return true;- return true
- }
- function isCirclePrime(n) {
- let strN = n.toString();
- for (let i = 1; i<strN.length; i++) {
- strN = shiftString(strN);
- if (!isPrime(parseInt(strN)))
- return false
- }
- return true;
- }
- function shiftString(str) {
- return str.substring(1) + str.substring(0,1);
- }
package com.mystuff.juststuff; import java.text.*; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.TreeSet; 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(); /* 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 found if (regularDate.equals(palDate)) palSet.add(startCal.getTime()); startCal.add(Calendar.DAY_OF_MONTH, 1); } return palSet; } 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 java.text.SimpleDateFormat;- import java.text.*;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.GregorianCalendar;
- import java.util.TreeSet;
public class Palindrome{- public class Palindrome {
- SimpleDateFormat sdf;
public Palindrome(){- public Palindrome() {
- this.sdf = new SimpleDateFormat("MMddyyyy");
- sdf.setLenient(false);
- }
public TreeSet<Date> countDatePalindromes(Date startDate, Date endDate){- public TreeSet<Date> countDatePalindromes(Date startDate, Date endDate) {
- TreeSet<Date> palSet = new TreeSet<Date>();
- GregorianCalendar startCal = new GregorianCalendar();
- GregorianCalendar endCal = new GregorianCalendar();
if (startDate.getTime() > endDate.getTime()){// end date is chronologically before start date. flip them.// System.out.println("end is before start. must flip. start: " + sdf.format(startDate.getTime()) + " end: " + sdf.format(endDate.getTime()));- /*
- 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{// start date is chronologically prior to end date. just set the calendars as such.- }else {
- startCal.setTime(startDate);
- endCal.setTime(endDate);
- }
// System.out.println("start should be before end. start: " + sdf.format(startCal.getTime()) + " end: " + sdf.format(endCal.getTime()));- String regularDate = null;
- String palDate = null;
while ( (startCal.before(endCal)) || (startCal.equals(endCal)) ){- while ( (startCal.before(endCal)) || (startCal.equals(endCal)) ) {
- regularDate = sdf.format(startCal.getTime());
palDate = palindromify(startCal.getTime());- palDate = palindromify(startCal.getTime());
- // a date palindrome was found
- if (regularDate.equals(palDate))
{// a date palindrome was found// System.out.println("Found one! regular: " + regularDate + " palindrome: " + palDate);- palSet.add(startCal.getTime());
}- startCal.add(Calendar.DAY_OF_MONTH, 1);
}// System.out.println("I found " + palSet.size() + " palindromes");- }
- return palSet;
- }
private String palindromify(final Date arg){SimpleDateFormat sdf = new SimpleDateFormat("MMddyyyy");sdf.setLenient(false);- private String palindromify(final Date arg) {
- StringBuffer palBuff = new StringBuffer(8);
String pal = sdf.format(arg);for (int i = pal.length(); i >= 1; i--){palBuff.append(pal.charAt(i - 1));}return palBuff.toString();- palBuff = sdf.format(arg, palBuff, new FieldPosition(0));
- return palBuff.reverse().toString();
- }
- }
This uses lambda expressions insted of return.
using System.Linq; public class Kata { public static string[] LiningUpHisStudents(string s) => s.Split(' ').OrderByDescending(x => x.Length).ThenByDescending(x => x).ToArray(); }
using System;- using System.Linq;
public class Kata{public static string[] LiningUpHisStudents(string s){var query = s.Split(' ').OrderByDescending(x => x.Length).ThenByDescending(x => x).ToArray();return query;}}- public class Kata { public static string[] LiningUpHisStudents(string s) => s.Split(' ').OrderByDescending(x => x.Length).ThenByDescending(x => x).ToArray(); }
namespace Solution { using NUnit.Framework; using System; [TestFixture] public class SolutionTest { [Test] public void MyTest() { string s = "Tadashi Takahiro Takao Takashi Takayuki Takehiko Takeo Takeshi Takeshi"; string[] S = { "Takehiko", "Takayuki", "Takahiro", "Takeshi", "Takeshi", "Takashi", "Tadashi", "Takeo", "Takao" }; string[] Test = Kata.LiningUpHisStudents(s); CollectionAssert.AreEqual(Kata.LiningUpHisStudents(s), S); } } }
- namespace Solution {
- using NUnit.Framework;
- using System;
// TODO: Replace examples and use TDD development by writing your own tests- [TestFixture]
- public class SolutionTest
- {
- [Test]
- public void MyTest()
- {
- string s = "Tadashi Takahiro Takao Takashi Takayuki Takehiko Takeo Takeshi Takeshi";
- string[] S = { "Takehiko", "Takayuki", "Takahiro", "Takeshi", "Takeshi", "Takashi", "Tadashi", "Takeo", "Takao" };
- string[] Test = Kata.LiningUpHisStudents(s);
- CollectionAssert.AreEqual(Kata.LiningUpHisStudents(s), S);
- }
- }
- }
def divisors(n) fact = [] for i in 1.. (Math.sqrt(n)).floor if n % i == 0 fact << i # more rubyish i think fact << (n / i) if (n / i) != i end end # no need for "return" in ruby fact.sort end
- def divisors(n)
fact = [];- fact = []
- for i in 1.. (Math.sqrt(n)).floor
- if n % i == 0
- fact << i
if n / i != ifact << n / iend- # more rubyish i think
- fact << (n / i) if (n / i) != i
- end
- end
fact.sort!return fact- # no need for "return" in ruby
- fact.sort
- end