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.
function dumbRockPaperScissors(player1, player2) { let size1 = 0; for (let i = 0; i < player1.length; i++) { for (let j = 0; j < player1.length; j++) { if (i === j) { size1++; } } } let size2 = 0; for (let i = 0; i < player2.length; i++) { for (let j = 0; j < player2.length; j++) { if (i === j) { size2++; } } } if (size1 === size2) { return 'Draw'; } if (size1 > size2) { if ( (player1 === 'Rock' && player2 === 'Scissors') || (player1 === 'Scissors' && player2 === 'Paper') || (player1 === 'Paper' && player2 === 'Rock') ) { return 'Player 1 wins'; } else { return 'Player 2 wins'; } } else { if ( (player2 === 'Rock' && player1 === 'Scissors') || (player2 === 'Scissors' && player1 === 'Paper') || (player2 === 'Paper' && player1 === 'Rock') ) { return 'Player 2 wins'; } else { return 'Player 1 wins'; } } }
- function dumbRockPaperScissors(player1, player2) {
- let size1 = 0;
- for (let i = 0; i < player1.length; i++) {
- for (let j = 0; j < player1.length; j++) {
- if (i === j) {
- size1++;
- }
- }
- }
}- let size2 = 0;
- for (let i = 0; i < player2.length; i++) {
- for (let j = 0; j < player2.length; j++) {
- if (i === j) {
- size2++;
- }
- }
- }
- if (size1 === size2) {
- return 'Draw';
- }
- if (size1 > size2) {
- if (
- (player1 === 'Rock' && player2 === 'Scissors') ||
- (player1 === 'Scissors' && player2 === 'Paper') ||
- (player1 === 'Paper' && player2 === 'Rock')
- ) {
- return 'Player 1 wins';
- } else {
- return 'Player 2 wins';
- }
- } else {
- if (
- (player2 === 'Rock' && player1 === 'Scissors') ||
- (player2 === 'Scissors' && player1 === 'Paper') ||
- (player2 === 'Paper' && player1 === 'Rock')
- ) {
- return 'Player 2 wins';
- } else {
- return 'Player 1 wins';
- }
- }
- }
const firstNonRepeatingCharacter = (str) => { const charCounts = new Map(); for (let i = 0; i < str.length; i++) { charCounts.set(str[i], (charCounts.get(str[i]) || 0) + 1); } for (let i = 0; i < str.length; i++) { if (charCounts.get(str[i]) === 1) { return str[i]; } } return null; }; // def first_non_repeating_character(str) // char_counts = Hash.new(0) // str.each_char { |char| char_counts[char] += 1 } // str.each_char do |char| // return char if char_counts[char] == 1 // end // nil // end
- const firstNonRepeatingCharacter = (str) => {
- const charCounts = new Map();
- for (let i = 0; i < str.length; i++) {
let seenDuplicate = false;for (let j = 0; j < str.length; j++) {if (str[i] === str[j] && i !== j) {seenDuplicate = true;break;}}if (!seenDuplicate) {- charCounts.set(str[i], (charCounts.get(str[i]) || 0) + 1);
- }
- for (let i = 0; i < str.length; i++) {
- if (charCounts.get(str[i]) === 1) {
- return str[i];
- }
- }
return null; // return null if no unique character is found};- return null;
- };
- // def first_non_repeating_character(str)
- // char_counts = Hash.new(0)
- // str.each_char { |char| char_counts[char] += 1 }
- // str.each_char do |char|
- // return char if char_counts[char] == 1
- // end
- // nil
- // end
function digitToText(digit) { return ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'][digit] }
const nums = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']- function digitToText(digit) {
return nums[digit]- return ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'][digit]
- }
fn digits(mut n: u64) -> usize { std::iter::from_fn(|| { n /= 10; Some(n) }) .take_while(|&n| n > 0) .count() + 1 }
- fn digits(mut n: u64) -> usize {
std::iter::from_fn(|| { n = n / 10; Some(n) }).take_while(|n| *n > 0)- std::iter::from_fn(|| { n /= 10; Some(n) })
- .take_while(|&n| n > 0)
- .count() + 1
- }
#[cfg(test)] mod tests { use super::*; #[test] fn pow10() { assert_eq!(digits(1), 1); assert_eq!(digits(10), 2); assert_eq!(digits(100), 3); assert_eq!(digits(1000), 4); assert_eq!(digits(10000), 5); assert_eq!(digits(100000), 6); assert_eq!(digits(1000000), 7); assert_eq!(digits(10000000), 8); assert_eq!(digits(100000000), 9); assert_eq!(digits(1000000000), 10); assert_eq!(digits(10000000000), 11); assert_eq!(digits(100000000000), 12); assert_eq!(digits(1000000000000), 13); assert_eq!(digits(10000000000000), 14); assert_eq!(digits(100000000000000), 15); assert_eq!(digits(1000000000000000), 16); assert_eq!(digits(10000000000000000), 17); assert_eq!(digits(100000000000000000), 18); assert_eq!(digits(1000000000000000000), 19); assert_eq!(digits(10000000000000000000), 20); } #[test] fn pow10_minus_1() { assert_eq!(digits(9), 1); assert_eq!(digits(99), 2); assert_eq!(digits(999), 3); assert_eq!(digits(9999), 4); assert_eq!(digits(99999), 5); assert_eq!(digits(999999), 6); assert_eq!(digits(9999999), 7); assert_eq!(digits(99999999), 8); assert_eq!(digits(999999999), 9); assert_eq!(digits(9999999999), 10); assert_eq!(digits(99999999999), 11); assert_eq!(digits(999999999999), 12); assert_eq!(digits(9999999999999), 13); assert_eq!(digits(99999999999999), 14); assert_eq!(digits(999999999999999), 15); assert_eq!(digits(9999999999999999), 16); assert_eq!(digits(99999999999999999), 17); assert_eq!(digits(999999999999999999), 18); assert_eq!(digits(9999999999999999999), 19); } #[test] fn pow10_half() { assert_eq!(digits(5), 1); assert_eq!(digits(50), 2); assert_eq!(digits(500), 3); assert_eq!(digits(5000), 4); assert_eq!(digits(50000), 5); assert_eq!(digits(500000), 6); assert_eq!(digits(5000000), 7); assert_eq!(digits(50000000), 8); assert_eq!(digits(500000000), 9); assert_eq!(digits(5000000000), 10); assert_eq!(digits(50000000000), 11); assert_eq!(digits(500000000000), 12); assert_eq!(digits(5000000000000), 13); assert_eq!(digits(50000000000000), 14); assert_eq!(digits(500000000000000), 15); assert_eq!(digits(5000000000000000), 16); assert_eq!(digits(50000000000000000), 17); assert_eq!(digits(500000000000000000), 18); assert_eq!(digits(5000000000000000000), 19); } }
#[test]fn pow10() {assert_eq!(digits(0), 1);let mut n = 1;assert_eq!(digits(1), 1);for i in 1..20 {n*=10;assert_eq!(digits(n), i+1);}assert_eq!(digits(std::u64::MAX), 20);}- #[cfg(test)]
- mod tests {
- use super::*;
- #[test]
- fn pow10() {
- assert_eq!(digits(1), 1);
- assert_eq!(digits(10), 2);
- assert_eq!(digits(100), 3);
- assert_eq!(digits(1000), 4);
- assert_eq!(digits(10000), 5);
- assert_eq!(digits(100000), 6);
- assert_eq!(digits(1000000), 7);
- assert_eq!(digits(10000000), 8);
- assert_eq!(digits(100000000), 9);
- assert_eq!(digits(1000000000), 10);
- assert_eq!(digits(10000000000), 11);
- assert_eq!(digits(100000000000), 12);
- assert_eq!(digits(1000000000000), 13);
- assert_eq!(digits(10000000000000), 14);
- assert_eq!(digits(100000000000000), 15);
- assert_eq!(digits(1000000000000000), 16);
- assert_eq!(digits(10000000000000000), 17);
- assert_eq!(digits(100000000000000000), 18);
- assert_eq!(digits(1000000000000000000), 19);
- assert_eq!(digits(10000000000000000000), 20);
- }
#[test]fn pow10_minus_1() {let mut n = 1;for i in 1..20 {n*=10;assert_eq!(digits(n - 1), i);}}- #[test]
- fn pow10_minus_1() {
- assert_eq!(digits(9), 1);
- assert_eq!(digits(99), 2);
- assert_eq!(digits(999), 3);
- assert_eq!(digits(9999), 4);
- assert_eq!(digits(99999), 5);
- assert_eq!(digits(999999), 6);
- assert_eq!(digits(9999999), 7);
- assert_eq!(digits(99999999), 8);
- assert_eq!(digits(999999999), 9);
- assert_eq!(digits(9999999999), 10);
- assert_eq!(digits(99999999999), 11);
- assert_eq!(digits(999999999999), 12);
- assert_eq!(digits(9999999999999), 13);
- assert_eq!(digits(99999999999999), 14);
- assert_eq!(digits(999999999999999), 15);
- assert_eq!(digits(9999999999999999), 16);
- assert_eq!(digits(99999999999999999), 17);
- assert_eq!(digits(999999999999999999), 18);
- assert_eq!(digits(9999999999999999999), 19);
- }
#[test]fn pow10_half() {let mut n = 1;for i in 1..20 {n*=10;assert_eq!(digits(n / 2), i);}}- #[test]
- fn pow10_half() {
- assert_eq!(digits(5), 1);
- assert_eq!(digits(50), 2);
- assert_eq!(digits(500), 3);
- assert_eq!(digits(5000), 4);
- assert_eq!(digits(50000), 5);
- assert_eq!(digits(500000), 6);
- assert_eq!(digits(5000000), 7);
- assert_eq!(digits(50000000), 8);
- assert_eq!(digits(500000000), 9);
- assert_eq!(digits(5000000000), 10);
- assert_eq!(digits(50000000000), 11);
- assert_eq!(digits(500000000000), 12);
- assert_eq!(digits(5000000000000), 13);
- assert_eq!(digits(50000000000000), 14);
- assert_eq!(digits(500000000000000), 15);
- assert_eq!(digits(5000000000000000), 16);
- assert_eq!(digits(50000000000000000), 17);
- assert_eq!(digits(500000000000000000), 18);
- assert_eq!(digits(5000000000000000000), 19);
- }
- }
use std::ops::Shr; fn div2<T: Shr<i32, Output = T>>(a: T) -> T { a >> 1 }
unsigned long long div2(unsigned long long a){//Use binary operators...I-Oreturn a >> 1;- use std::ops::Shr;
- fn div2<T: Shr<i32, Output = T>>(a: T) -> T {
- a >> 1
- }
#[cfg(test)] mod tests { use super::*; #[test] fn under_10() { assert_eq!(div2(10_u8), 5); assert_eq!(div2(0_u16), 0); assert_eq!(div2(3_u32), 1); } #[test] fn huge_numbers() { assert_eq!(div2(65536_u64), 32768); assert_eq!(div2(1234567890_i32), 617283945); assert_eq!(div2(6553665535_i64), 3276832767); assert_eq!(div2(200000000000000000_i128), 100000000000000000); } }
// TODO: Replace examples and use TDD by writing your own testsDescribe(d2){It(under10){Assert::That(div2(10), Equals(5));Assert::That(div2(0), Equals(0));Assert::That(div2(3), Equals(1));- #[cfg(test)]
- mod tests {
- use super::*;
- #[test]
- fn under_10() {
- assert_eq!(div2(10_u8), 5);
- assert_eq!(div2(0_u16), 0);
- assert_eq!(div2(3_u32), 1);
- }
It(huge_numbers){Assert::That(div2(65536), Equals(32768));Assert::That(div2(6553665535), Equals(3276832767));Assert::That(div2(1234567890), Equals(617283945));- #[test]
- fn huge_numbers() {
- assert_eq!(div2(65536_u64), 32768);
- assert_eq!(div2(1234567890_i32), 617283945);
- assert_eq!(div2(6553665535_i64), 3276832767);
- assert_eq!(div2(200000000000000000_i128), 100000000000000000);
- }
};- }