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.
use std::collections::BTreeSet; fn first_non_repeating_character(s: &str) -> Option<char> { let mut seen = Vec::new(); let mut repeated = BTreeSet::new(); for c in s.chars() { if repeated.contains(&c) { continue; } if let Some(idx) = seen.iter().position(|&ch| ch == c) { seen.remove(idx); repeated.insert(c); } else { seen.push(c); } } seen.first().copied() }
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;}- use std::collections::BTreeSet;
- fn first_non_repeating_character(s: &str) -> Option<char> {
- let mut seen = Vec::new();
- let mut repeated = BTreeSet::new();
- for c in s.chars() {
- if repeated.contains(&c) {
- continue;
- }
if (!seenDuplicate) {return str[i];- if let Some(idx) = seen.iter().position(|&ch| ch == c) {
- seen.remove(idx);
- repeated.insert(c);
- } else {
- seen.push(c);
- }
- }
return null; // return null if no unique character is found};- seen.first().copied()
- }
#[test] fn test() { assert_eq!(first_non_repeating_character("abcd"), Some('a')); assert_eq!(first_non_repeating_character("aabbcdc"), Some('d')); assert_eq!(first_non_repeating_character("a@b@bc"), Some('a')); assert_eq!(first_non_repeating_character("aabbcc"), None); assert_eq!(first_non_repeating_character("z"), Some('z')); assert_eq!(first_non_repeating_character(""), None); assert_eq!(first_non_repeating_character("1122a"), Some('a')); assert_eq!(first_non_repeating_character("1122a"), Some('a')); assert_eq!(first_non_repeating_character(&format!("{}{}c", "a".repeat(10_000), "b".repeat(10_000))), Some('c')); assert_eq!(first_non_repeating_character(&format!("{}{}", "a".repeat(20_000), "b".repeat(20_000))), None); }
// 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('should return the first non-repeating character', function() {assert.strictEqual(firstNonRepeatingCharacter('abcd'), 'a');assert.strictEqual(firstNonRepeatingCharacter('aabbcdc'), 'd');});it('should return the first non-repeating character when special characters are included', function() {assert.strictEqual(firstNonRepeatingCharacter('a@b@bc'), 'a');});it('should return null when all characters are repeating', function() {assert.strictEqual(firstNonRepeatingCharacter('aabbcc'), null);});it('should return the first character if it is the only one', function() {assert.strictEqual(firstNonRepeatingCharacter('z'), 'z');});it('should handle an empty string correctly', function() {assert.strictEqual(firstNonRepeatingCharacter(''), null);});it('should handle strings with numbers', function() {assert.strictEqual(firstNonRepeatingCharacter('1122a'), 'a');});it('should handle very long strings with the non-repeating character at the end', function() {const longString = 'a'.repeat(10000) + 'b'.repeat(10000) + 'c';assert.strictEqual(firstNonRepeatingCharacter(longString), 'c');});it('should handle very long strings with all characters repeating', function() {const longString = 'a'.repeat(20000) + 'b'.repeat(20000);assert.strictEqual(firstNonRepeatingCharacter(longString), null);});});- #[test]
- fn test() {
- assert_eq!(first_non_repeating_character("abcd"), Some('a'));
- assert_eq!(first_non_repeating_character("aabbcdc"), Some('d'));
- assert_eq!(first_non_repeating_character("a@b@bc"), Some('a'));
- assert_eq!(first_non_repeating_character("aabbcc"), None);
- assert_eq!(first_non_repeating_character("z"), Some('z'));
- assert_eq!(first_non_repeating_character(""), None);
- assert_eq!(first_non_repeating_character("1122a"), Some('a'));
- assert_eq!(first_non_repeating_character("1122a"), Some('a'));
- assert_eq!(first_non_repeating_character(&format!("{}{}c", "a".repeat(10_000), "b".repeat(10_000))), Some('c'));
- assert_eq!(first_non_repeating_character(&format!("{}{}", "a".repeat(20_000), "b".repeat(20_000))), None);
- }
const nums = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'] const digitToText = nums.at.bind(nums) ?? 'idk'
- const nums = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
function digitToText(digit) {return nums[digit]}- const digitToText = nums.at.bind(nums) ?? 'idk'
const cinema_auditorium = (spisok2D,ryad)=> { var output = (spisok2D[ryad].reduce((summaStulev,stulya ) => summaStulev + stulya, 0)); console.log(output); var stulya = spisok2D[ryad].reduce((summaStulev,stulya ) => summaStulev + stulya, 0); return stulya; }
- const cinema_auditorium = (spisok2D,ryad)=> {
console.log(spisok2D,ryad)return 3- var output = (spisok2D[ryad].reduce((summaStulev,stulya ) => summaStulev + stulya, 0));
- console.log(output);
- var stulya = spisok2D[ryad].reduce((summaStulev,stulya ) => summaStulev + stulya, 0);
- return stulya;
- }
Moves the actions into a nested object, where the first level is Player1's action and the second layer Player 2's action.
This makes the templating easier.
also added an "Invalid action!" error if either player makes an invalid move.
function rps(player1, player2) { const actions = { rock: { paper: 2, scissors: 1, rock: 0, }, paper: { paper: 0, scissors: 2, rock: 1, }, scissors: { paper: 1, scissors: 0, rock: 2, }, }; const result = actions?.[player1]?.[player2]; if (result === 0) return "Draw!"; if (!result) throw "Invalid action!"; return `Player ${result} won!`; }
- function rps(player1, player2) {
return player1 == player2 ? 'Draw!' :player1 == 'rock' && player2 == 'scissors' ||player1 == 'scissors' && player2 == 'paper' ||player1 == 'paper' && player2 == 'rock' ? 'Player 1 won!' : 'Player 2 won!';}- const actions = {
- rock: {
- paper: 2,
- scissors: 1,
- rock: 0,
- },
- paper: {
- paper: 0,
- scissors: 2,
- rock: 1,
- },
- scissors: {
- paper: 1,
- scissors: 0,
- rock: 2,
- },
- };
- const result = actions?.[player1]?.[player2];
- if (result === 0) return "Draw!";
- if (!result) throw "Invalid action!";
- return `Player ${result} won!`;
- }
use std::ops::Add; fn add<T: Add<Output = T>>(a: T, b: T) -> T { a.add(b) }
// write a add function that doesn't use the plus symbolfunction add(a, b){return a + b;}- use std::ops::Add;
// Make sure to view the test cases to see how this test fails- fn add<T: Add<Output = T>>(a: T, b: T) -> T {
- a.add(b)
- }
#[cfg(test)] mod tests { use super::*; use std::fs::read_to_string; #[test] fn doesnt_contain_plus() { let solution = read_to_string("./src/lib.rs").unwrap(); let solution_without_test = solution.split_once("#[cfg(test)]").unwrap().0; assert!(!solution_without_test.contains("+")); } #[test] fn correct_addition() { assert_eq!(add(1, 1), 2); assert_eq!(add(1, -1), 0); assert_eq!(add(101, 202), 303); assert_eq!(add(-1, -1), -2); } }
const fs = require('fs');const solution = fs.readFileSync('/home/codewarrior/solution.txt', 'utf8');describe("Check Solution", function(){it("should prevent the '+' symbol from being used anywhere in the code", function(){Test.expect(solution.indexOf('+') == -1, "Your code isn't allowed to include the + symbol!");});});- #[cfg(test)]
- mod tests {
- use super::*;
- use std::fs::read_to_string;
- #[test]
- fn doesnt_contain_plus() {
- let solution = read_to_string("./src/lib.rs").unwrap();
- let solution_without_test = solution.split_once("#[cfg(test)]").unwrap().0;
- assert!(!solution_without_test.contains("+"));
- }
- #[test]
- fn correct_addition() {
- assert_eq!(add(1, 1), 2);
- assert_eq!(add(1, -1), 0);
- assert_eq!(add(101, 202), 303);
- assert_eq!(add(-1, -1), -2);
- }
- }
.
const numMinusSeven = function(num) { return num - 7; }
- const numMinusSeven = function(num) {
let youGoodBro = [];while (num > 0) {num -= 7;youGoodBro.push(num);}return youGoodBro.length;- return num - 7;
- }
const chai = require("chai"); const assert = chai.assert; chai.config.truncateThreshold = 0; const Test = require("@codewars/test-compat"); describe("Test", function() { it("should test for 1000", function() { Test.assertEquals(numMinusSeven(1000), 993); }); it("should test for 100", function() { Test.assertEquals(numMinusSeven(100), 93); }); it("should test for 10", function() { Test.assertEquals(numMinusSeven(10), 3); }); });
- const chai = require("chai");
- const assert = chai.assert;
- chai.config.truncateThreshold = 0;
- const Test = require("@codewars/test-compat");
- describe("Test", function() {
- it("should test for 1000", function() {
Test.assertEquals(numMinusSeven(1000), 143);- Test.assertEquals(numMinusSeven(1000), 993);
- });
- it("should test for 100", function() {
Test.assertEquals(numMinusSeven(100), 15);- Test.assertEquals(numMinusSeven(100), 93);
- });
- it("should test for 10", function() {
Test.assertEquals(numMinusSeven(10), 2);- Test.assertEquals(numMinusSeven(10), 3);
- });
- });