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.
macro_rules! your_name { () => { your_name!("Taki") }; ($name: expr) => { format!("Hello {}, you are very kool!", $name) }; }
def your_name(n="Taki"):return "Hello "+n+", you are very kool!"- macro_rules! your_name {
- () => { your_name!("Taki") };
- ($name: expr) => { format!("Hello {}, you are very kool!", $name) };
- }
#[test] fn test() { assert_eq!(your_name!(), "Hello Taki, you are very kool!"); assert_eq!(your_name!("Alice"), "Hello Alice, you are very kool!"); }
import codewars_test as test# TODO Write testsimport solution # or from solution import example# 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(your_name(), 'Hello Taki, you are very kool!')test.assert_equals(your_name("monkey_on_a_keyboard_1"), 'Hello monkey_on_a_keyboard_1, you are very kool!')- #[test]
- fn test() {
- assert_eq!(your_name!(), "Hello Taki, you are very kool!");
- assert_eq!(your_name!("Alice"), "Hello Alice, you are very kool!");
- }
fn shortest_word_length(s: &str) -> usize { s.split_whitespace().map(str::len).min().unwrap_or(0) }
import java.util.stream.*; public class Kata { public static int findShort(String s) { return Stream.of(s.split(" ")) .mapToInt(String::length) .min() .getAsInt(); } }- fn shortest_word_length(s: &str) -> usize {
- s.split_whitespace().map(str::len).min().unwrap_or(0)
- }
#[test] fn test() { assert_eq!(shortest_word_length(""), 0); assert_eq!(shortest_word_length("1"), 1); assert_eq!(shortest_word_length("12"), 2); assert_eq!(shortest_word_length("123 1234"), 3); assert_eq!(shortest_word_length("maybe who knows perhaps"), 3); assert_eq!(shortest_word_length("random test cases are easier"), 3); assert_eq!(shortest_word_length("poetry degree bespeaks bewildering naivetee"), 6); }
import org.junit.Test;import static org.junit.Assert.assertEquals;/*** Created by Javatlacati on 01/03/2017.*/public class KataTest {@Testpublic void findShort() throws Exception {assertEquals(3, Kata.findShort("bitcoin take over the world maybe who knows perhaps"));assertEquals(3, Kata.findShort("turns out random test cases are easier than writing out basic ones"));}- #[test]
- fn test() {
- assert_eq!(shortest_word_length(""), 0);
- assert_eq!(shortest_word_length("1"), 1);
- assert_eq!(shortest_word_length("12"), 2);
- assert_eq!(shortest_word_length("123 1234"), 3);
- assert_eq!(shortest_word_length("maybe who knows perhaps"), 3);
- assert_eq!(shortest_word_length("random test cases are easier"), 3);
- assert_eq!(shortest_word_length("poetry degree bespeaks bewildering naivetee"), 6);
- }
fn lol() -> fn() -> fn() -> fn() -> u32 { fn lol() -> fn() -> fn() -> u32 { fn lol() -> fn() -> u32 { fn lol() -> u32 { 100 } lol } lol } lol }
def n(n=100):def lol():def lol():def lol():nonlocal nif n:lol=lambda:100return lol()else:return lol()return lolreturn lolreturn lol()()()- fn lol() -> fn() -> fn() -> fn() -> u32 {
- fn lol() -> fn() -> fn() -> u32 {
- fn lol() -> fn() -> u32 {
- fn lol() -> u32 {
- 100
- }
- lol
- }
- lol
- }
- lol
- }
#[test] fn test() { assert_eq!(lol()()()(), 100); }
Test.assert_equals(n(),100)- #[test]
- fn test() {
- assert_eq!(lol()()()(), 100);
- }
fn nand(a: bool, b: bool) -> bool { !(a && b) } fn not(a: bool) -> bool { nand(a, a) } fn and(a: bool, b: bool) -> bool { not(nand(a, b)) } fn or(a: bool, b: bool) -> bool { nand(not(a), not(b)) } fn nor(a: bool, b: bool) -> bool { not(or(a, b)) } fn xor(a: bool, b: bool) -> bool { and(nand(a, b), or(a, b)) } fn xnor(a: bool, b: bool) -> bool { not(xor(a, b)) }
def NOT(a):if a=="1":return "0"elif a=="0":return "1"def BUF(a):if a=="1":return "1"elif a=="0":return "0"def AND(a,b):if a=="1" and b=="1":return "1"else:return "0"def OR(a,b):if a=="0" and b=="0":return "0"else:return "1"def NAND(a,b):return NOT(AND(a,b))- fn nand(a: bool, b: bool) -> bool {
- !(a && b)
- }
def NOR(a,b):return NOT(OR(a,b))- fn not(a: bool) -> bool {
- nand(a, a)
- }
def XOR(a,b):return OR(AND(a,b),NOR(a,b))- fn and(a: bool, b: bool) -> bool {
- not(nand(a, b))
- }
def XNOR(a,b):return NOT(XOR(a,b))- fn or(a: bool, b: bool) -> bool {
- nand(not(a), not(b))
- }
- fn nor(a: bool, b: bool) -> bool {
- not(or(a, b))
- }
- fn xor(a: bool, b: bool) -> bool {
- and(nand(a, b), or(a, b))
- }
- fn xnor(a: bool, b: bool) -> bool {
- not(xor(a, b))
- }
#[cfg(test)] mod tests { use super::*; #[test] fn test_nand() { assert!(!nand(true, true)); assert!(nand(true, false)); assert!(nand(false, true)); assert!(nand(false, false)); } #[test] fn test_not() { assert!(!not(true)); assert!(not(false)); } #[test] fn test_and() { assert!(and(true, true)); assert!(!and(true, false)); assert!(!and(false, true)); assert!(!and(false, false)); } #[test] fn test_or() { assert!(or(true, true)); assert!(or(true, false)); assert!(or(false, true)); assert!(!or(false, false)); } #[test] fn test_nor() { assert!(!nor(true, true)); assert!(!nor(true, false)); assert!(!nor(false, true)); assert!(nor(false, false)); } #[test] fn test_xor() { assert!(!xor(true, true)); assert!(xor(false, true)); assert!(xor(true, false)); assert!(!xor(false, false)); } #[test] fn text_xnor() { assert!(xnor(true, true)); assert!(!xnor(false, true)); assert!(!xnor(true, false)); assert!(xnor(false, false)); } }
import codewars_test as test# TODO Write testsimport solution # or from solution import example- #[cfg(test)]
- mod tests {
- use super::*;
# 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]
- fn test_nand() {
- assert!(!nand(true, true));
- assert!(nand(true, false));
- assert!(nand(false, true));
- assert!(nand(false, false));
- }
- #[test]
- fn test_not() {
- assert!(!not(true));
- assert!(not(false));
- }
- #[test]
- fn test_and() {
- assert!(and(true, true));
- assert!(!and(true, false));
- assert!(!and(false, true));
- assert!(!and(false, false));
- }
- #[test]
- fn test_or() {
- assert!(or(true, true));
- assert!(or(true, false));
- assert!(or(false, true));
- assert!(!or(false, false));
- }
- #[test]
- fn test_nor() {
- assert!(!nor(true, true));
- assert!(!nor(true, false));
- assert!(!nor(false, true));
- assert!(nor(false, false));
- }
- #[test]
- fn test_xor() {
- assert!(!xor(true, true));
- assert!(xor(false, true));
- assert!(xor(true, false));
- assert!(!xor(false, false));
- }
- #[test]
- fn text_xnor() {
- assert!(xnor(true, true));
- assert!(!xnor(false, true));
- assert!(!xnor(true, false));
- assert!(xnor(false, false));
- }
- }
fn binary_search(arr: &[i32], val: i32) -> Option<usize> { arr.binary_search(&val).ok() }
#returns the index of val if val is in the array, else -1 if val is not in the array.#precondition: arr must be sorted in ascending orderdef binary_search(arr,val):i=-1j=len(arr)while i+1!=j:m=i+(j-i)//2if arr[m]<val:i=melif arr[m]>val:j=melse:return mreturn -1- fn binary_search(arr: &[i32], val: i32) -> Option<usize> {
- arr.binary_search(&val).ok()
- }
#[test] fn test() { assert_eq!(binary_search(&[1,2,3,4,5,6,7,8], 3), Some(2)); assert_eq!(binary_search(&[1,2,3,4,5,6,7,8], 100), None); assert_eq!(binary_search(&[1,2,3,4,5,6,7,8], -1), None); assert_eq!(binary_search(&[0], 0), Some(0)); assert_eq!(binary_search(&[0], -10), None); assert_eq!(binary_search(&[0], 10), None); assert_eq!(binary_search(&[], 42), None); }
import codewars_test as test# TODO Write tests# import solution # or from solution import examplefrom solution import binary_search# test.assert_equals(actual, expected, [optional] message)arr=[1,2,3,4,5,6,7,8]val1=3val2=100val3=-1arr2=[0]val4=0val5=-10val6=10empty=[]val10=42@test.describe("Example")def test_group():@test.it("test case")def test_case():test.assert_equals(binary_search(arr,val1), 2)test.assert_equals(binary_search(arr,val2), -1)test.assert_equals(binary_search(arr,val3), -1)test.assert_equals(binary_search(arr2,val4), 0)test.assert_equals(binary_search(arr2,val5), -1)test.assert_equals(binary_search(arr2,val6), -1)test.assert_equals(binary_search(empty,val10), -1)- #[test]
- fn test() {
- assert_eq!(binary_search(&[1,2,3,4,5,6,7,8], 3), Some(2));
- assert_eq!(binary_search(&[1,2,3,4,5,6,7,8], 100), None);
- assert_eq!(binary_search(&[1,2,3,4,5,6,7,8], -1), None);
- assert_eq!(binary_search(&[0], 0), Some(0));
- assert_eq!(binary_search(&[0], -10), None);
- assert_eq!(binary_search(&[0], 10), None);
- assert_eq!(binary_search(&[], 42), None);
- }
use rand::seq::SliceRandom; const EYES: [char; 4] = [':', ';', '=', 'X']; const ACCESSORIES: [char; 5] = ['\'', '.', '-', '~', '^']; const MOUTHS: [char; 10] = [']', '}', ')', '>', 'D', '\\', '(', '[', '{', 'O']; fn random_face() -> String { let mut rng = rand::thread_rng(); format!( "{}{}{}", EYES.choose(&mut rng).unwrap(), ACCESSORIES.choose(&mut rng).unwrap(), MOUTHS.choose(&mut rng).unwrap() ) }
from random import choiceeyes=":;=X"accessory=["","'",".","-","~","^",""]mouth="]})>D|\\([{O"def random_smiley():return choice(eyes)+choice(accessory)+choice(mouth)- use rand::seq::SliceRandom;
def many_faces():acc=[]for _ in range(100):acc.append(random_smiley())return " ".join(acc)- const EYES: [char; 4] = [':', ';', '=', 'X'];
- const ACCESSORIES: [char; 5] = ['\'', '.', '-', '~', '^'];
- const MOUTHS: [char; 10] = [']', '}', ')', '>', 'D', '\\', '(', '[', '{', 'O'];
# def garfield_the_1000_faced():# acc=[]# for _ in range(100)- fn random_face() -> String {
- let mut rng = rand::thread_rng();
- format!(
- "{}{}{}",
- EYES.choose(&mut rng).unwrap(),
- ACCESSORIES.choose(&mut rng).unwrap(),
- MOUTHS.choose(&mut rng).unwrap()
- )
- }
#[cfg(test)] mod tests { use super::*; #[test] fn test_eyes() { for _ in 0..100 { assert!(EYES.contains(&random_face().chars().next().unwrap())); } } #[test] fn test_accessories() { for _ in 0..100 { assert!(ACCESSORIES.contains(&random_face().chars().nth(1).unwrap())); } } #[test] fn test_mouths() { for _ in 0..100 { assert!(MOUTHS.contains(&random_face().chars().nth(2).unwrap())); } } }
import codewars_test as test# TODO Write testsimport solution # or from solution import example# test.assert_equals(actual, expected, [optional] message)@test.describe("Example")def test_group():@test.it("test case")def test_case():print(random_smiley())print(many_faces())test.assert_equals(True, True)- #[cfg(test)]
- mod tests {
- use super::*;
- #[test]
- fn test_eyes() {
- for _ in 0..100 {
- assert!(EYES.contains(&random_face().chars().next().unwrap()));
- }
- }
- #[test]
- fn test_accessories() {
- for _ in 0..100 {
- assert!(ACCESSORIES.contains(&random_face().chars().nth(1).unwrap()));
- }
- }
- #[test]
- fn test_mouths() {
- for _ in 0..100 {
- assert!(MOUTHS.contains(&random_face().chars().nth(2).unwrap()));
- }
- }
- }
mod preloaded; use preloaded::Stats; use std::cmp::Ordering; const THRESHOLD: u32 = 8; fn compute_progress(trainee: Stats, milestone: Stats) -> &'static str { let attendance = check(trainee.attendance, milestone.attendance); let codewars = check(milestone.codewars, trainee.codewars); let tests = check(trainee.tests, milestone.tests); let pulls = check(trainee.pull_requests, milestone.pull_requests); let sum_factors = attendance + codewars + tests + pulls; match sum_factors.cmp(&THRESHOLD) { Ordering::Greater => "Beyond Milestone", Ordering::Equal => "At Milestone", Ordering::Less => "Behind Milestone" } } fn check(a: u32, b: u32) -> u32 { match a.cmp(&b) { Ordering::Greater => 3, Ordering::Equal => 2, Ordering::Less => 1, } }
const Deepa = {attendance: 100,tests: 4,codewars: 7,pullRequests: 12}const Bilal = {attendance: 95,tests: 3,codewars: 7,pullRequests: 12}const milestoneDay = {attendance: 100,tests: 4,codewars: 7,pullRequests: 12}- mod preloaded;
- use preloaded::Stats;
- use std::cmp::Ordering;
const computeProgress = (trainee, milestone) => {const comparator = Object.entries(milestoneDay).length * 2;const checkMilestone = (factor, milestone) => factor > milestone ? 3 : factor === milestone ? 2 : 1;// codewars ranks go downconst checkCodewars = (factor, milestone) => factor < milestone ? 3 : factor === milestone ? 2 : 1;- const THRESHOLD: u32 = 8;
// 1 behind, 2 at, 3 ahead, and there are currently 4 measures// therefore at each milestone 8 is the currently the comparator- fn compute_progress(trainee: Stats, milestone: Stats) -> &'static str {
- let attendance = check(trainee.attendance, milestone.attendance);
- let codewars = check(milestone.codewars, trainee.codewars);
- let tests = check(trainee.tests, milestone.tests);
- let pulls = check(trainee.pull_requests, milestone.pull_requests);
- let sum_factors = attendance + codewars + tests + pulls;
- match sum_factors.cmp(&THRESHOLD) {
- Ordering::Greater => "Beyond Milestone",
- Ordering::Equal => "At Milestone",
- Ordering::Less => "Behind Milestone"
- }
- }
let attendance = checkMilestone(trainee.attendance, milestone.attendance);let codewars = checkCodewars(trainee.codewars, milestone.codewars);let tests = checkMilestone(trainee.tests, milestone.tests);let pulls = checkMilestone(trainee.pullRequests, milestone.pullRequests);const sumFactors = codewars + tests + attendance + pulls;return sumFactors > comparator ? 'Beyond Milestone' : sumFactors === comparator ? 'At Milestone' : 'Behind Milestone'- fn check(a: u32, b: u32) -> u32 {
- match a.cmp(&b) {
- Ordering::Greater => 3,
- Ordering::Equal => 2,
- Ordering::Less => 1,
- }
- }
#[cfg(test)] mod tests { use super::*; const DEEPA: Stats = Stats { attendance: 100, tests: 4, codewars: 7, pull_requests: 12 }; const BILAL: Stats = Stats { attendance: 95, tests: 3, codewars: 7, pull_requests: 12 }; const MILESTONE_DAY: Stats = Stats { attendance: 100, tests: 4, codewars: 7, pull_requests: 12 }; #[test] fn test_at_milestone() { assert_eq!(compute_progress(DEEPA, MILESTONE_DAY), "At Milestone"); } #[test] fn test_behind_milestone() { assert_eq!(compute_progress(BILAL, MILESTONE_DAY), "Behind Milestone"); } }
// 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("Solution", function() {it("Deepa should be At Milestone", function() {assert.equal('At Milestone', computeProgress(Deepa,milestoneDay))});it("Bilal should be Behind Milestone", function() {assert.equal('Behind Milestone', computeProgress(Bilal,milestoneDay))});});- #[cfg(test)]
- mod tests {
- use super::*;
- const DEEPA: Stats = Stats {
- attendance: 100,
- tests: 4,
- codewars: 7,
- pull_requests: 12
- };
- const BILAL: Stats = Stats {
- attendance: 95,
- tests: 3,
- codewars: 7,
- pull_requests: 12
- };
- const MILESTONE_DAY: Stats = Stats {
- attendance: 100,
- tests: 4,
- codewars: 7,
- pull_requests: 12
- };
- #[test]
- fn test_at_milestone() {
- assert_eq!(compute_progress(DEEPA, MILESTONE_DAY), "At Milestone");
- }
- #[test]
- fn test_behind_milestone() {
- assert_eq!(compute_progress(BILAL, MILESTONE_DAY), "Behind Milestone");
- }
- }