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 codewars_test as test # TODO Write tests import solution # or from solution import example # test.assert_equals(actual, expected, [optional] message) @test.describe("Check:") def test_group(): @test.it("Some simple cases") def test_case(): test.assert_equals(power(2,5), 2**5) test.assert_equals(power(3,50), 3**50) test.assert_equals(power(2,200), 2**200) test.assert_equals(power(200,0), 1) test.assert_equals(power(2, -5), 2 ** -5) test.assert_equals(power(-3, 5), (-3) ** 5) test.assert_equals(power(2, -200), 2 ** -200) test.assert_equals(power(-200, 0), 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("Check:")
- def test_group():
- @test.it("Some simple cases")
- def test_case():
- test.assert_equals(power(2,5), 2**5)
- test.assert_equals(power(3,50), 3**50)
- test.assert_equals(power(2,200), 2**200)
- test.assert_equals(power(200,0), 1)
- test.assert_equals(power(2, -5), 2 ** -5)
- test.assert_equals(power(-3, 5), (-3) ** 5)
- test.assert_equals(power(2, -200), 2 ** -200)
- test.assert_equals(power(-200, 0), 1)
Shorter number converter, Using a if instead of a switch.
def converter(number): nums = ['zero', 'one','two','three','four','five','six','seven','eight','nine'] if number < len(nums): return nums[int(number)] else: return number
- def converter(number):
match number:case 0:return 'zero'case 1:return 'one'case 2:return 'two'case 3:return 'three'case 4:return 'four'case 5:return 'five'case 6:return 'six'case 7:return 'seven'case 8:return 'eight'case 9:return 'nine'case _:return number- nums = ['zero', 'one','two','three','four','five','six','seven','eight','nine']
- if number < len(nums):
- return nums[int(number)]
- else:
- return number
Create a function that checks if a number n is divisible by two numbers x AND y. All inputs are positive, non-zero digits.
Examples:
- n = 3, x = 1, y = 3 => true because 3 is divisible by 1 and 3
- n = 12, x = 2, y = 6 => true because 12 is divisible by 2 and 6
- n = 100, x = 5, y = 3 => false because 100 is not divisible by 3
- n = 12, x = 7, y = 5 => false because 12 is neither divisible by 7 nor 5
pub fn is_divisible(n: i32, x: i32, y:i32) -> bool { match (n % x == 0, n % y == 0) { (true, true) => true, _ => false } }
function isDivisible(n, x, y) {if (n % x === 0 && n % y === 0) {return true} else {return false}- pub fn is_divisible(n: i32, x: i32, y:i32) -> bool {
- match (n % x == 0, n % y == 0) {
- (true, true) => true,
- _ => false
- }
- }
#[cfg(test)] mod tests { use crate::is_divisible; #[test] fn it_should_return_true() { let expected : bool = true; let result_zero : bool = is_divisible(0, 1, 3); let result_positive : bool = is_divisible(3, 1, 3); let result_negative : bool = is_divisible(-3, 1, 3); assert_eq!(expected, result_zero); assert_eq!(expected, result_positive); assert_eq!(expected, result_negative); } #[test] fn it_should_return_false() { let expected : bool = false; let result_positive : bool = is_divisible(3, 2, 3); let result_negative : bool = is_divisible(-3, 2, 3); assert_eq!(expected, result_positive); assert_eq!(expected, result_negative); } }
const chai = require("chai");const assert = chai.assert;chai.config.truncateThreshold=0;describe("Basic tests", () => {it("Fixed Tests", () => {assert.strictEqual(isDivisible(3,3,4),false);assert.strictEqual(isDivisible(12,3,4),true);assert.strictEqual(isDivisible(8,3,4),false);assert.strictEqual(isDivisible(48,3,4),true);});});- #[cfg(test)]
- mod tests {
- use crate::is_divisible;
- #[test]
- fn it_should_return_true() {
- let expected : bool = true;
- let result_zero : bool = is_divisible(0, 1, 3);
- let result_positive : bool = is_divisible(3, 1, 3);
- let result_negative : bool = is_divisible(-3, 1, 3);
- assert_eq!(expected, result_zero);
- assert_eq!(expected, result_positive);
- assert_eq!(expected, result_negative);
- }
- #[test]
- fn it_should_return_false() {
- let expected : bool = false;
- let result_positive : bool = is_divisible(3, 2, 3);
- let result_negative : bool = is_divisible(-3, 2, 3);
- assert_eq!(expected, result_positive);
- assert_eq!(expected, result_negative);
- }
- }
In this Kata your job is to find the biggest Integer in an Array and return it as such.
'1,2,3,4' -> '4'
The Integers passed can be non-negativ but will always be valid numbers.
import java.util.*; public class Kata { public static int findMax(int[] my_array) { int max = my_array[0]; for(int i : my_array) { if(i > max) max = i; } return max; } }
- import java.util.*;
- public class Kata {
- public static int findMax(int[] my_array) {
// Write a method that returns the largest integer in the list.// You can assume that the list has at least one element.Arrays.sort(my_array);return (my_array[my_array.length-1]);- int max = my_array[0];
- for(int i : my_array) {
- if(i > max) max = i;
- }
- return max;
- }
- }
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; // TODO: Write more tests to prove your code bleow class SolutionTest { @Test void testSomething() { assertEquals(Kata.findMax(new int[]{4, 5, 6, 7}), 7); assertEquals(Kata.findMax(new int[]{24, 4, 50, 12}), 50); assertEquals(Kata.findMax(new int[]{2, 8, 64, 4, 16, 32}), 64); assertEquals(Kata.findMax(new int[]{-5, -24, -8, -8}), -5); } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- // TODO: Write more tests to prove your code bleow
- class SolutionTest {
- @Test
- void testSomething() {
- assertEquals(Kata.findMax(new int[]{4, 5, 6, 7}), 7);
- assertEquals(Kata.findMax(new int[]{24, 4, 50, 12}), 50);
- assertEquals(Kata.findMax(new int[]{2, 8, 64, 4, 16, 32}), 64);
- assertEquals(Kata.findMax(new int[]{-5, -24, -8, -8}), -5);
- }
- }
import re def to_camel_case(s: str): return '' if s == '' else ''.join([el.capitalize() if i == 0 and not ''.join(s)[0].islower() else el.lower() if i == 0 and ''.join(s)[0].islower() else el.capitalize() for (i, el) in enumerate(re.split(re.compile(r'[-_ ]') , s))])
def to_camel_case(text: str):split_chars = "-_"# loop over each character abovefor split_char in split_chars:split_parts = text.split(split_char)# skip if there was nothing to split onif len(split_parts) == 1:continueparts = []# break up the string in to it's partsfor i, item in enumerate(split_parts):# save the first part but don't change the case of the first letterif i == 0:parts.append(item)continueparts.append(f"{item[0].upper()}{item[1:]}")# join the parts and overwrite the text variable for the next looptext = "".join(parts)return text- import re
- def to_camel_case(s: str):
- return '' if s == '' else ''.join([el.capitalize() if i == 0 and not ''.join(s)[0].islower() else el.lower() if i == 0 and ''.join(s)[0].islower() else el.capitalize() for (i, el) in enumerate(re.split(re.compile(r'[-_ ]') , s))])
added two new functions Nor and Nand
bool Or(bool a, bool b) { return a+b; } bool And(bool a, bool b) { return a*b; } bool Xor(bool a, bool b) { return a!=b; } bool Nor(bool a, bool b) { return !(a+b); } bool Nand(bool a, bool b) { return !(a*b); }
- bool Or(bool a, bool b) {
- return a+b;
- }
- bool And(bool a, bool b) {
- return a*b;
- }
- bool Xor(bool a, bool b) {
- return a!=b;
- }
- bool Nor(bool a, bool b) {
- return !(a+b);
- }
- bool Nand(bool a, bool b) {
- return !(a*b);
- }
// TODO: Replace examples and use TDD development by writing your own tests Describe(AND_OR_XOR) { It(AND) { Assert::That(And(true, false), Equals(false)); Assert::That(And(false, true), Equals(false)); Assert::That(And(true, true), Equals(true)); Assert::That(And(false, false), Equals(false)); } It(OR) { Assert::That(Or(true, false), Equals(true)); Assert::That(Or(false, true), Equals(true)); Assert::That(Or(true, true), Equals(true)); Assert::That(Or(false, false), Equals(false)); } It(XOR) { Assert::That(Xor(true, false), Equals(true)); Assert::That(Xor(false, true), Equals(true)); Assert::That(Xor(true, true), Equals(false)); Assert::That(Xor(false, false), Equals(false)); } It(NOR) { Assert::That(Nor(true, false), Equals(false)); Assert::That(Nor(false, true), Equals(false)); Assert::That(Nor(true, true), Equals(false)); Assert::That(Nor(false, false), Equals(true)); } It(NAND) { Assert::That(Nand(true, false), Equals(true)); Assert::That(Nand(false, true), Equals(true)); Assert::That(Nand(true, true), Equals(false)); Assert::That(Nand(false, false), Equals(true)); } };
- // TODO: Replace examples and use TDD development by writing your own tests
- Describe(AND_OR_XOR)
- {
- It(AND)
- {
- Assert::That(And(true, false), Equals(false));
- Assert::That(And(false, true), Equals(false));
- Assert::That(And(true, true), Equals(true));
- Assert::That(And(false, false), Equals(false));
- }
- It(OR)
- {
- Assert::That(Or(true, false), Equals(true));
- Assert::That(Or(false, true), Equals(true));
- Assert::That(Or(true, true), Equals(true));
- Assert::That(Or(false, false), Equals(false));
- }
- It(XOR)
- {
- Assert::That(Xor(true, false), Equals(true));
- Assert::That(Xor(false, true), Equals(true));
- Assert::That(Xor(true, true), Equals(false));
- Assert::That(Xor(false, false), Equals(false));
- }
- It(NOR)
- {
- Assert::That(Nor(true, false), Equals(false));
- Assert::That(Nor(false, true), Equals(false));
- Assert::That(Nor(true, true), Equals(false));
- Assert::That(Nor(false, false), Equals(true));
- }
- It(NAND)
- {
- Assert::That(Nand(true, false), Equals(true));
- Assert::That(Nand(false, true), Equals(true));
- Assert::That(Nand(true, true), Equals(false));
- Assert::That(Nand(false, false), Equals(true));
- }
- };