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.
Make the matching of the operator character more readable
fn math(s: &str) -> i32 { // remove whitespace characters so all we have left are digits and the operator let math_str: String = s.chars().filter(|ch| !ch.is_whitespace()).collect(); // find the position of the operator character let pos: usize = math_str .chars() .position(|ch| match ch { '+' | '-' | '*' | '/' | '=' => true, _ => false }) .expect("invalid operator, expected +, -, *, / or ="); // extract the two numbers from the string let num1: i32 = math_str[..pos].parse().unwrap(); let num2: i32 = math_str[pos + 1..].parse().unwrap(); match &math_str[pos..=pos] { "+" => num1 + num2, "-" => num1 - num2, "*" => num1 * num2, "/" => num1 / num2, _ => (num1 == num2) as i32, } }
- fn math(s: &str) -> i32 {
- // remove whitespace characters so all we have left are digits and the operator
- let math_str: String = s.chars().filter(|ch| !ch.is_whitespace()).collect();
- // find the position of the operator character
- let pos: usize = math_str
- .chars()
.position(|ch| ch == '+' || ch == '-' || ch == '*' || ch == '/' || ch == '=')- .position(|ch| match ch {
- '+' | '-' | '*' | '/' | '=' => true,
- _ => false
- })
- .expect("invalid operator, expected +, -, *, / or =");
- // extract the two numbers from the string
- let num1: i32 = math_str[..pos].parse().unwrap();
- let num2: i32 = math_str[pos + 1..].parse().unwrap();
match &math_str[pos..pos + 1] {- match &math_str[pos..=pos] {
- "+" => num1 + num2,
- "-" => num1 - num2,
- "*" => num1 * num2,
- "/" => num1 / num2,
- _ => (num1 == num2) as i32,
- }
- }
var tr = { "I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000 } function solution (roman_string) { return roman_string.split('').map((letter, index, a) => { const current_value = tr[letter]; const next_value = tr[a[index+1]]; return next_value && current_value < next_value ? (- current_value) : current_value; }).reduce((acc, item) => acc + item, 0); }
- var tr = {
- "I": 1,
- "V": 5,
- "X": 10,
- "L": 50,
- "C": 100,
- "D": 500,
- "M": 1000
- }
function solution (roman) {letters = roman.split('');var res = 0;letters.forEach((cur, i) => {var next = letters[i + 1];if (tr[next] && tr[cur] < tr[next]) {res -= tr[cur];} else {res += tr[cur];}})return res;- function solution (roman_string) {
- return roman_string.split('').map((letter, index, a) => {
- const current_value = tr[letter];
- const next_value = tr[a[index+1]];
- return next_value && current_value < next_value ?
- (- current_value) : current_value;
- }).reduce((acc, item) => acc + item, 0);
- }
const strictEqual = require('chai').assert.strictEqual; function doTest (romanString, expected) { const actual = solution(romanString); strictEqual(actual, expected, `for roman number ${romanString}`); } describe("Tests", () => { it("sample tests", () => { doTest('XXI', 21); doTest('I', 1); doTest('IV', 4); doTest('MMVIII', 2008); doTest('MDCLXVI', 1666); doTest('MMMDCCXXIV', 3724); }); });
- const strictEqual = require('chai').assert.strictEqual;
- function doTest (romanString, expected) {
- const actual = solution(romanString);
- strictEqual(actual, expected, `for roman number ${romanString}`);
- }
- describe("Tests", () => {
- it("sample tests", () => {
- doTest('XXI', 21);
- doTest('I', 1);
- doTest('IV', 4);
- doTest('MMVIII', 2008);
- doTest('MDCLXVI', 1666);
- doTest('MMMDCCXXIV', 3724);
- });
- });