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.
I use this whenever I have to add another directory to my PATH
environment variable in my .bashrc
. This way I don't have duplicates.
I wrote this years ago and it's hacky and kind of dumb... I'm sure it can be improved.
add_PATH() {
oIFS=$IFS
IFS=':'
t=(${PATH})
unset IFS
t=("$1" ${t[@]%%"$1"})
# output the new array
IFS=':'
echo -n "${t[*]}"
unset t
IFS=$oIFS
}
echo "Original Path: $PATH"
export PATH=$(add_PATH /usr/local/bin)
echo "New Path: $PATH"
- added compile-time template
- added random test for runtime function
- replaced
x * 2
withx << 1
constexpr int doubleValue(int x) { return x << 1; } template<int x> struct Double { static constexpr int value = (x << 1); };
#include<iostream>int doubleValue(int x) {return x * 2;- constexpr int doubleValue(int x) {
- return x << 1;
- }
- template<int x> struct Double {
- static constexpr int value = (x << 1);
- };
#include <random> std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution dist(-1000000000, 1000000000); Describe(Sample_Tests) { It(Runtime_Test) { for (int i = 0; i < 100; ++i) { int arg = dist(gen); Assert::That(doubleValue(arg), Equals(arg * 2)); } } It(Compile_Time_Test) { const int arg = 10; char arr[Double<arg>::value]; Assert::That(sizeof(arr), Equals(arg * 2)); } };
// TODO: Replace examples and use TDD by writing your own testsDescribe(sampleTests) {It(shouldBe) {Assert::That(doubleValue(5), Equals(10));- #include <random>
- std::random_device rd;
- std::mt19937 gen(rd());
- std::uniform_int_distribution dist(-1000000000, 1000000000);
- Describe(Sample_Tests) {
- It(Runtime_Test) {
- for (int i = 0; i < 100; ++i) {
- int arg = dist(gen);
- Assert::That(doubleValue(arg), Equals(arg * 2));
- }
- }
- It(Compile_Time_Test) {
- const int arg = 10;
- char arr[Double<arg>::value];
- Assert::That(sizeof(arr), Equals(arg * 2));
- }
- };
function dumbRockPaperScissors(player1, player2) { const OBJECTS = ['Rock', 'Paper', 'Scissors']; return player1 === OBJECTS[0] && player2=== OBJECTS[0] || player1 === OBJECTS[1] && player2=== OBJECTS[1] || player1 === OBJECTS[2] && player2=== OBJECTS[2] ? 'Draw' : player1=== OBJECTS[0] && player2=== OBJECTS[1] || player1=== OBJECTS[1] && player2=== OBJECTS[2] || player1=== OBJECTS[2] && player2=== OBJECTS[0] ? 'Player 2 wins' : 'Player 1 wins'; }
- function dumbRockPaperScissors(player1, player2) {
if(player1 == "Rock" && player2 == "Paper"){return "Player 2 wins";}else if(player1 == "Rock" && player2 == "Scissors" ){return "Player 1 wins";}else if(player1 == "Scissors" && player2 == "Paper"){return "Player 1 wins";}else if(player1 == "Scissors" && player2 == "Rock"){return "Player 2 wins";}else if(player1 == "Paper" && player2 == "Scissors"){return "Player 2 wins";}else if(player1 == "Paper" && player2 == "Rock"){return "Player 1 wins";}else if(player1 == "Paper" && player2 == "Paper"){return "Draw";}else if(player1 == "Rock" && player2 == "Rock"){return "Draw";}else if(player1 == "Scissors" && player2 == "Scissors"){return "Draw";}- const OBJECTS = ['Rock', 'Paper', 'Scissors'];
- return player1 === OBJECTS[0] && player2=== OBJECTS[0] ||
- player1 === OBJECTS[1] && player2=== OBJECTS[1] ||
- player1 === OBJECTS[2] && player2=== OBJECTS[2] ? 'Draw' :
- player1=== OBJECTS[0] && player2=== OBJECTS[1] ||
- player1=== OBJECTS[1] && player2=== OBJECTS[2] ||
- player1=== OBJECTS[2] && player2=== OBJECTS[0] ? 'Player 2 wins' :
- 'Player 1 wins';
- }
const firstNonRepeatingCharacter = (str) => { const charCount = {}; for (const char of str) { charCount[char] = (charCount[char] || 0) + 1; } for (const char of str) { if (charCount[char] === 1) { return char; } } return null; };
- const firstNonRepeatingCharacter = (str) => {
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) {return str[i];- const charCount = {};
- for (const char of str) {
- charCount[char] = (charCount[char] || 0) + 1;
- }
- for (const char of str) {
- if (charCount[char] === 1) {
- return char;
- }
- }
return null; // return null if no unique character is found- return null;
- };
const nums = [ {0 : "zero"}, {1 : "one"}, {2 : "two"}, {3 : "three"}, {4 : "four"}, {5 : "five"}, {6 : "six"}, {7 : "seven"}, {8 : "eight"}, {9 : "nine"} ] function digitToText(digit) { if(digit > 9 || digit < 0){ return undefined }else{ return nums[digit][digit] } }
const nums = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']- const nums = [
- {0 : "zero"},
- {1 : "one"},
- {2 : "two"},
- {3 : "three"},
- {4 : "four"},
- {5 : "five"},
- {6 : "six"},
- {7 : "seven"},
- {8 : "eight"},
- {9 : "nine"}
- ]
- function digitToText(digit) {
return nums[digit]- if(digit > 9 || digit < 0){
- return undefined
- }else{
- return nums[digit][digit]
- }
- }
fn reverse(mut n: u32) -> u32 { let mut reversed = 0; while n > 0 { reversed *= 10; reversed += n % 10; n /= 10; } reversed }
public class Algorithms {public static int reverseInt(int n) {int reversed = 0;while(n != 0){reversed = reversed * 10 + (n % 10);n /= 10;- fn reverse(mut n: u32) -> u32 {
- let mut reversed = 0;
- while n > 0 {
- reversed *= 10;
- reversed += n % 10;
- n /= 10;
- }
return reversed;}}- reversed
- }
#[test] fn test() { assert_eq!(reverse(12345), 54321); }
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 reverseIntTest() {assertEquals(54321, Algorithms.reverseInt(12345));}- #[test]
- fn test() {
- assert_eq!(reverse(12345), 54321);
- }
#include <vector> using namespace std; int result ( vector <int> sum ) { if ( sum.size() == 0 ) return 0; int somma_totale = 0; for ( int i = 0; i < sum.size(); i++ ) { somma_totale = somma_totale + sum[i]; } return somma_totale; }
def sum(arr):result = 0for i in arr:result += ireturn result- #include <vector>
- using namespace std;
- int result ( vector <int> sum ) {
- if ( sum.size() == 0 )
- return 0;
- int somma_totale = 0;
- for ( int i = 0; i < sum.size(); i++ ) {
- somma_totale = somma_totale + sum[i];
- } return somma_totale;
- }