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.
Added proper handling of characters that expand when capitalized.
Ajouté la propre gestion des caractères qui se multiplient lorsqu'ils sont capitalisés.
fn maestro_split(s: &str) -> String { let milieu = s.chars().count() / 2; let mut lettres = s.chars(); let côté_gauche: String = (&mut lettres).take(milieu).flat_map(char::to_lowercase).collect(); let lettre_majuscule = lettres.next().map(|c| c.to_uppercase().to_string()).unwrap_or_default(); let côté_droite: String = lettres.flat_map(char::to_lowercase).collect(); format!("{lettre_majuscule}{côté_droite}{côté_gauche}") } fn approche_naïf(s: &str) -> String { if s.is_empty() { return String::new(); } let mid = s.len() / 2; format!("{}{}{}", s[mid..mid+1].to_uppercase(), s[mid+1..].to_lowercase(), s[..mid].to_lowercase()) }
function maestroSplit(string) {let newWord = string.slice(parseInt(string.length / 2)) + string.slice(0, parseInt(string.length / 2));return newWord.toLowerCase().charAt(0).toUpperCase() + newWord.toLowerCase().slice(1);- fn maestro_split(s: &str) -> String {
- let milieu = s.chars().count() / 2;
- let mut lettres = s.chars();
- let côté_gauche: String = (&mut lettres).take(milieu).flat_map(char::to_lowercase).collect();
- let lettre_majuscule = lettres.next().map(|c| c.to_uppercase().to_string()).unwrap_or_default();
- let côté_droite: String = lettres.flat_map(char::to_lowercase).collect();
- format!("{lettre_majuscule}{côté_droite}{côté_gauche}")
- }
- fn approche_naïf(s: &str) -> String {
- if s.is_empty() {
- return String::new();
- }
- let mid = s.len() / 2;
- format!("{}{}{}", s[mid..mid+1].to_uppercase(), s[mid+1..].to_lowercase(), s[..mid].to_lowercase())
- }
#[cfg(test)] mod tests { use super::*; #[test] fn test_ascii() { assert_eq!(maestro_split("verLan"), "Lanver"); assert_eq!(maestro_split("Maestro"), "Stromae"); assert_eq!(maestro_split("MaEsTrO"), "Stromae"); assert_eq!(maestro_split("wArScODE"), "Codewars"); assert_eq!(maestro_split(""), ""); } #[test] fn test_unicode() { assert_eq!(maestro_split("français"), "Çaisfran"); assert_eq!(maestro_split("Æther"), "Heræt"); assert_eq!(maestro_split("𱁬ဪ⸻"), "ဪ⸻𱁬"); assert_eq!(maestro_split("heißen"), "SSenhei"); } #[test] fn test_naïf_correct() { assert_eq!(approche_naïf("verLan"), "Lanver"); assert_eq!(approche_naïf("Maestro"), "Stromae"); assert_eq!(approche_naïf("MaEsTrO"), "Stromae"); assert_eq!(approche_naïf("wArScODE"), "Codewars"); assert_eq!(approche_naïf(""), ""); } #[test] #[should_panic] fn test_naïf_panique1() { approche_naïf("français"); } #[test] #[should_panic] fn test_naïf_panique2() { approche_naïf("heißen"); } #[test] #[should_panic] fn test_naïf_panique3() { approche_naïf("𱁬ဪ⸻"); } }
// 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("maestroSplit", function() {it("should transform verLan to Lanver", () => {Test.assertEquals(maestroSplit("verLan"), "Lanver");});it("should transform français to Çaisfran", () => {Test.assertEquals(maestroSplit("français"), "Çaisfran");});it("should transform Maestro to Stromae", () => {// Test.assertEquals(1 + 1, 2);// assert.strictEqual(1 + 1, 2);Test.assertEquals(maestroSplit("Maestro"), "Stromae");});it("should transform MaEsTrO to Stromae", () => {Test.assertEquals(maestroSplit("MaEsTrO"), "Stromae");});it("should transform warscode to Codewars", () => {Test.assertEquals(maestroSplit("wArScODE"), "Codewars");});});- #[cfg(test)]
- mod tests {
- use super::*;
- #[test]
- fn test_ascii() {
- assert_eq!(maestro_split("verLan"), "Lanver");
- assert_eq!(maestro_split("Maestro"), "Stromae");
- assert_eq!(maestro_split("MaEsTrO"), "Stromae");
- assert_eq!(maestro_split("wArScODE"), "Codewars");
- assert_eq!(maestro_split(""), "");
- }
- #[test]
- fn test_unicode() {
- assert_eq!(maestro_split("français"), "Çaisfran");
- assert_eq!(maestro_split("Æther"), "Heræt");
- assert_eq!(maestro_split("𱁬ဪ⸻"), "ဪ⸻𱁬");
- assert_eq!(maestro_split("heißen"), "SSenhei");
- }
- #[test]
- fn test_naïf_correct() {
- assert_eq!(approche_naïf("verLan"), "Lanver");
- assert_eq!(approche_naïf("Maestro"), "Stromae");
- assert_eq!(approche_naïf("MaEsTrO"), "Stromae");
- assert_eq!(approche_naïf("wArScODE"), "Codewars");
- assert_eq!(approche_naïf(""), "");
- }
- #[test] #[should_panic]
- fn test_naïf_panique1() {
- approche_naïf("français");
- }
- #[test] #[should_panic]
- fn test_naïf_panique2() {
- approche_naïf("heißen");
- }
- #[test] #[should_panic]
- fn test_naïf_panique3() {
- approche_naïf("𱁬ဪ⸻");
- }
- }
fn other_angle(angle1: u32, angle2: u32) -> u32 { 180 - (angle1 + angle2) }
public class ThirdAngle {public static int otherAngle(int angle1, int angle2) {return 180-(angle1+angle2);}- fn other_angle(angle1: u32, angle2: u32) -> u32 {
- 180 - (angle1 + angle2)
- }
#[test] fn test() { assert_eq!(other_angle(40, 80), 60); assert_eq!(other_angle(108, 24), 48); assert_eq!(other_angle(5, 5), 170); assert_eq!(other_angle(90, 0), 90); }
import org.junit.Test;import static org.junit.Assert.assertEquals;import org.junit.runners.JUnit4;// TODO: Replace examples and use TDD development by writing your own testspublic class SolutionTest {@Testpublic void testSomething() {// assertEquals("expected", "actual");}- #[test]
- fn test() {
- assert_eq!(other_angle(40, 80), 60);
- assert_eq!(other_angle(108, 24), 48);
- assert_eq!(other_angle(5, 5), 170);
- assert_eq!(other_angle(90, 0), 90);
- }
fn find_index(slice: &[i32], value: i32) -> Option<usize> { slice.iter().position(|&num| num == value) }
public class Kata {public static int findIndex (int[] my_array, int t) {// Find the index of treturn 4;}- fn find_index(slice: &[i32], value: i32) -> Option<usize> {
- slice.iter().position(|&num| num == value)
- }
#[test] fn test() { let array = [1, 2, 5, 7, 10]; assert_eq!(find_index(&array, 1), Some(0)); assert_eq!(find_index(&array, 2), Some(1)); assert_eq!(find_index(&array, 5), Some(2)); assert_eq!(find_index(&array, 7), Some(3)); assert_eq!(find_index(&array, 10), Some(4)); assert_eq!(find_index(&array, -1), None); }
import org.junit.jupiter.api.Test;import static org.junit.jupiter.api.Assertions.assertEquals;// TODO: Replace examples and use TDD by writing your own testsclass SolutionTest {@Testvoid testSomething() {int[] randomArray = {1, 2, 5, 7};assertEquals(2, Kata.findIndex(randomArray, 5));}}- #[test]
- fn test() {
- let array = [1, 2, 5, 7, 10];
- assert_eq!(find_index(&array, 1), Some(0));
- assert_eq!(find_index(&array, 2), Some(1));
- assert_eq!(find_index(&array, 5), Some(2));
- assert_eq!(find_index(&array, 7), Some(3));
- assert_eq!(find_index(&array, 10), Some(4));
- assert_eq!(find_index(&array, -1), None);
- }
Given an array containing only 0s, 1s, and 2s; sort the array in ascending order.
fn sort_values(slice: &[u8]) -> Vec<u8> { let mut counts = [0, 0, 0]; for &num in slice { counts[num as usize] += 1; } counts .into_iter() .enumerate() .flat_map(|(num, count)| std::iter::repeat(num as u8).take(count)) .collect() }
public class Kata {public static int[] sortValues(int[] my_array, int size) {// Given an array of size N containing only 0s, 1s, and 2s;// sort the array in ascending order.int[] returnArray = {0,0,0,0,1,1,2,2};return returnArray;- fn sort_values(slice: &[u8]) -> Vec<u8> {
- let mut counts = [0, 0, 0];
- for &num in slice {
- counts[num as usize] += 1;
- }
- counts
- .into_iter()
- .enumerate()
- .flat_map(|(num, count)| std::iter::repeat(num as u8).take(count))
- .collect()
- }
#[cfg(test)] mod tests { use super::sort_values; #[test] fn test_simple() { assert_eq!(sort_values(&[0, 0, 2, 0, 1, 1, 2, 0]), [0, 0, 0, 0, 1, 1, 2, 2]); assert_eq!(sort_values(&[2, 0, 1, 2]), [0, 1, 2, 2]); } // times out if an inefficient approach like `.sort()` is used #[test] fn test_huge() { use std::iter::repeat; use rand::prelude::*; const LARGE_VALUE: usize = 25_000_000; let mut rng = rand::thread_rng(); let zeros = rng.gen_range(0..100) + LARGE_VALUE; let ones = rng.gen_range(0..100) + LARGE_VALUE; let twos = rng.gen_range(0..100) + LARGE_VALUE; let sorted = repeat(0).take(zeros) .chain(repeat(1).take(ones)) .chain(repeat(2).take(twos)) .collect::<Vec<_>>(); let mut shuffled = sorted.clone(); shuffled.shuffle(&mut rng); assert_eq!(sort_values(&shuffled), sorted); } }
import org.junit.jupiter.api.Test;import static org.junit.jupiter.api.Assertions.assertArrayEquals;// TODO: Replace examples and use TDD by writing your own testsclass SolutionTest {@Testvoid testSomething() {int[] inputArray = {0,0,2,0,1,1,2,0};int[] expectedArray = {0,0,0,0,1,1,2,2};assertArrayEquals(expectedArray, Kata.sortValues(inputArray, 8));- #[cfg(test)]
- mod tests {
- use super::sort_values;
- #[test]
- fn test_simple() {
- assert_eq!(sort_values(&[0, 0, 2, 0, 1, 1, 2, 0]), [0, 0, 0, 0, 1, 1, 2, 2]);
- assert_eq!(sort_values(&[2, 0, 1, 2]), [0, 1, 2, 2]);
- }
@Testvoid testSomethingElse() {int[] inputArray = {2, 0, 1, 2};int[] expectedArray = {0, 1, 2, 2};assertArrayEquals(expectedArray, Kata.sortValues(inputArray, 8));- // times out if an inefficient approach like `.sort()` is used
- #[test]
- fn test_huge() {
- use std::iter::repeat;
- use rand::prelude::*;
- const LARGE_VALUE: usize = 25_000_000;
- let mut rng = rand::thread_rng();
- let zeros = rng.gen_range(0..100) + LARGE_VALUE;
- let ones = rng.gen_range(0..100) + LARGE_VALUE;
- let twos = rng.gen_range(0..100) + LARGE_VALUE;
- let sorted = repeat(0).take(zeros)
- .chain(repeat(1).take(ones))
- .chain(repeat(2).take(twos))
- .collect::<Vec<_>>();
- let mut shuffled = sorted.clone();
- shuffled.shuffle(&mut rng);
- assert_eq!(sort_values(&shuffled), sorted);
- }
- }
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));
- }
- }