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.
import java.util.*; interface HighLow { static int[] printLargestAndSmallest(int[] nums) { Arrays.sort(nums); return new int[] {nums[0], nums[nums.length-1]}; } }
- import java.util.*;
- interface HighLow {
- static int[] printLargestAndSmallest(int[] nums) {
int min = nums[0], max = nums[0];for (int n : nums) {if (n < min) min = n;if (n > max) max = n;}return new int[] {min, max};- Arrays.sort(nums);
- return new int[] {nums[0], nums[nums.length-1]};
- }
- }
As far as I can tell, you don't want a simple number but a prime number.
I added 5075 as it's also not a prime number.
export const checkIsPrimeNumber = (n: number) => { if (!Number.isInteger(n)) return false; for (var i = 2; i < n; i++) { if (n % i === 0) return false; } return n > 1; };
export const checkIsNumberSimple = (number: number) => {// Check if the number is integerif (number % 1 != 0) return false;if (number < 2) return false;if (number != 2 && number % 2 == 0) return false;if (number != 3 && number % 3 == 0) return false;return true;- export const checkIsPrimeNumber = (n: number) =>
- {
- if (!Number.isInteger(n)) return false;
- for (var i = 2; i < n; i++) {
- if (n % i === 0) return false;
- }
- return n > 1;
- };
// See https://www.chaijs.com for how to use Chai. import { assert } from "chai"; import { checkIsPrimeNumber } from "./solution"; describe("Prime numbers", function() { it("should not be negative numbers", function() { assert.strictEqual(checkIsPrimeNumber(-1), false); }); it("should be integer numbers", function() { assert.strictEqual(checkIsPrimeNumber(3.1), false); }); it("should be prime numbers", function() { assert.strictEqual(checkIsPrimeNumber(2), true); assert.strictEqual(checkIsPrimeNumber(3), true); assert.strictEqual(checkIsPrimeNumber(5), true); assert.strictEqual(checkIsPrimeNumber(3571), true); assert.strictEqual(checkIsPrimeNumber(5075), false); assert.strictEqual(checkIsPrimeNumber(5077), true); assert.strictEqual(checkIsPrimeNumber(0), false); assert.strictEqual(checkIsPrimeNumber(1), false); assert.strictEqual(checkIsPrimeNumber(4), false); assert.strictEqual(checkIsPrimeNumber(3572), false); }); });
- // See https://www.chaijs.com for how to use Chai.
- import { assert } from "chai";
import { checkIsNumberSimple } from "./solution";- import { checkIsPrimeNumber } from "./solution";
// TODO Add your tests heredescribe("Simple numbers", function() {- describe("Prime numbers", function() {
- it("should not be negative numbers", function() {
assert.strictEqual(checkIsNumberSimple(-1), false);- assert.strictEqual(checkIsPrimeNumber(-1), false);
- });
- it("should be integer numbers", function() {
assert.strictEqual(checkIsNumberSimple(3.1), false);- assert.strictEqual(checkIsPrimeNumber(3.1), false);
- });
it("should be simple numbers", function() {assert.strictEqual(checkIsNumberSimple(2), true);assert.strictEqual(checkIsNumberSimple(3), true);assert.strictEqual(checkIsNumberSimple(5), true);assert.strictEqual(checkIsNumberSimple(3571), true);assert.strictEqual(checkIsNumberSimple(0), false);assert.strictEqual(checkIsNumberSimple(1), false);assert.strictEqual(checkIsNumberSimple(4), false);assert.strictEqual(checkIsNumberSimple(3572), false);- it("should be prime numbers", function() {
- assert.strictEqual(checkIsPrimeNumber(2), true);
- assert.strictEqual(checkIsPrimeNumber(3), true);
- assert.strictEqual(checkIsPrimeNumber(5), true);
- assert.strictEqual(checkIsPrimeNumber(3571), true);
- assert.strictEqual(checkIsPrimeNumber(5075), false);
- assert.strictEqual(checkIsPrimeNumber(5077), true);
- assert.strictEqual(checkIsPrimeNumber(0), false);
- assert.strictEqual(checkIsPrimeNumber(1), false);
- assert.strictEqual(checkIsPrimeNumber(4), false);
- assert.strictEqual(checkIsPrimeNumber(3572), false);
- });
- });
Only generate the values with fast-check.
const { assert } = require("chai"); const fc = require('fast-check'); describe("Solution", () => { it("should test for something", () => { const t = []; fc.check(fc.property(fc.integer(1, 100), fc.integer(1, 100), (...a) => t.push(a))); t.forEach(([a, b]) => { assert.equal(add(a, b), a + b); }); }); });
- const { assert } = require("chai");
- const fc = require('fast-check');
- describe("Solution", () => {
- it("should test for something", () => {
fc.assert(fc.property(fc.integer(1, 100), fc.integer(1, 100), (a, b) => {- const t = [];
- fc.check(fc.property(fc.integer(1, 100), fc.integer(1, 100), (...a) => t.push(a)));
- t.forEach(([a, b]) => {
- assert.equal(add(a, b), a + b);
}));- });
- });
- });
public static class Kata { public static bool IsOdd(int input, int div) { if (input % div == 0) return true; return false; } }
- public static class Kata
- {
public static bool IsOdd(int input)- public static bool IsOdd(int input, int div)
- {
if (input % 2 == 0){return false;}else{return true;}- if (input % div == 0)
- return true;
- return false;
- }
- }
namespace Solution { using NUnit.Framework; using System; // TODO: Replace examples and use TDD by writing your own tests [TestFixture] public class SolutionTest { [Test] public void MyTest() { Assert.AreEqual(true, Kata.IsOdd(1,1)); Assert.AreEqual(false, Kata.IsOdd(2,3)); Assert.AreEqual(true, Kata.IsOdd(12,3)); Assert.AreEqual(false, Kata.IsOdd(18284,13)); } } }
- namespace Solution {
- using NUnit.Framework;
- using System;
- // TODO: Replace examples and use TDD by writing your own tests
- [TestFixture]
- public class SolutionTest
- {
- [Test]
- public void MyTest()
- {
Assert.AreEqual(true, Kata.IsOdd(1));Assert.AreEqual(false, Kata.IsOdd(2));Assert.AreEqual(true, Kata.IsOdd(13));Assert.AreEqual(false, Kata.IsOdd(18284));- Assert.AreEqual(true, Kata.IsOdd(1,1));
- Assert.AreEqual(false, Kata.IsOdd(2,3));
- Assert.AreEqual(true, Kata.IsOdd(12,3));
- Assert.AreEqual(false, Kata.IsOdd(18284,13));
- }
- }
- }
The original author did not specify what to do in edgecases, so I added what I think is most sensible.
def abbrev(s): length = len(s) if length < 4: return s return s[0] + str(length - 2) + s[-1]
- def abbrev(s):
return s[0] + str(len(s[1:-1])) + s[-1]- length = len(s)
- if length < 4:
- return s
- return s[0] + str(length - 2) + s[-1]
import codewars_test as test # TODO Write tests import 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(abbrev('abcdefghijklmnopqrstuvwxyz'), 'a24z') test.assert_equals(abbrev('abc'), 'abc') test.assert_equals(abbrev('a'), 'a') test.assert_equals(abbrev(''), '')
- import codewars_test as test
- # TODO Write tests
- import 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(abbrev('abcdefghijklmnopqrstuvwxyz'), 'a24z')
- test.assert_equals(abbrev('abc'), 'abc')
- test.assert_equals(abbrev('a'), 'a')
- test.assert_equals(abbrev(''), '')
You have to create an abbreviation function. It will take string and return a string while taking the first and last char of word and replace the remaining with the number of chars in it.
For example:
internationalization => i18n
Localization => L10n
Deepak-Vishwa => D4k-V4a
I Love India => I L2e I3a
const abbrev = (text = "") => { return text.replace(/\w{4,}/g, s => { l = s.length; return `${s[0]}${l - 2}${s[l - 1]}`; }); };
const abbrevWord = (text = "") => {if (text.length < 3) return text;const first = text.charAt(0);const last = text.slice(-1);const remLen = text.length - 2;return `${first}${remLen}${last}`;};const simpleChars = /\w+/g;- const abbrev = (text = "") => {
return text.replace(simpleChars, (matched) => abbrevWord(matched));- return text.replace(/\w{4,}/g, s => {
- l = s.length;
- return `${s[0]}${l - 2}${s[l - 1]}`;
- });
- };
const Test = require("@codewars/test-compat"); describe("Solution", function() { it("should abbreviate single words", function() { Test.assertEquals(abbrev("internationalization"), "i18n"); Test.assertEquals(abbrev("Localization"), "L10n"); }); it("should abbreviate multiple words", function() { Test.assertEquals(abbrev("I Love India"), "I L2e I3a"); }); it("should abbreviate hyphenated words", function() { Test.assertEquals(abbrev("Deepak-Vishwa"), "D4k-V4a"); }); it("should not abbreviate single letters", function() { Test.assertEquals(abbrev("A"), "A"); }); it("should not abbreviate 2 letter words", function() { Test.assertEquals(abbrev("If"), "If"); }); it("should not abbreviate 3 letter words", function() { Test.assertEquals(abbrev("The"), "The"); }); it("should only abbreviate mutiple words of 4 letters or more", function() { Test.assertEquals(abbrev("The quick brown fox jumps over the lazy dog"), "The q3k b3n fox j3s o2r the l2y dog"); }); });
- const Test = require("@codewars/test-compat");
- describe("Solution", function() {
it("should test for something", function() {- it("should abbreviate single words", function() {
- Test.assertEquals(abbrev("internationalization"), "i18n");
- Test.assertEquals(abbrev("Localization"), "L10n");
Test.assertEquals(abbrev("Deepak-Vishwa"), "D4k-V4a");Test.assertEquals(abbrev("I Love India"), "I L2e I3a");- });
- it("should abbreviate multiple words", function() {
- Test.assertEquals(abbrev("I Love India"), "I L2e I3a");
- });
- it("should abbreviate hyphenated words", function() {
- Test.assertEquals(abbrev("Deepak-Vishwa"), "D4k-V4a");
- });
- it("should not abbreviate single letters", function() {
- Test.assertEquals(abbrev("A"), "A");
- });
- it("should not abbreviate 2 letter words", function() {
- Test.assertEquals(abbrev("If"), "If");
- });
- it("should not abbreviate 3 letter words", function() {
- Test.assertEquals(abbrev("The"), "The");
- });
- it("should only abbreviate mutiple words of 4 letters or more", function() {
- Test.assertEquals(abbrev("The quick brown fox jumps over the lazy dog"), "The q3k b3n fox j3s o2r the l2y dog");
- });
- });