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.
from math import sqrt #Same but with some memoization, better if you need to check some numbers more than once def prime(x, cache={}): if x not in cache: if x <= 1: cache[x]= False return False for i in range(2,int(sqrt(x))+1): if x % i is 0: cache[x] = False return False cache[x] = True return cache[x]
- from math import sqrt
- #Same but with some memoization, better if you need to check some numbers more than once
- def prime(x, cache={}):
- if x not in cache:
- if x <= 1:
- cache[x]= False
- return False
for i in range(2,int(sqrt(x))):- for i in range(2,int(sqrt(x))+1):
- if x % i is 0:
- cache[x] = False
- return False
- cache[x] = True
- return cache[x]
test.assert_equals(prime(12345),False) test.assert_equals(prime(36),False) test.assert_equals(prime(36),False) test.assert_equals(prime(0), False) test.assert_equals(prime(1), False) test.assert_equals(prime(2), True) test.assert_equals(prime(7), True) test.assert_equals(prime(13), True) test.assert_equals(prime(97), True) test.assert_equals(prime(29), True) test.assert_equals(prime(115249), True) test.assert_equals(prime(4), False)
- test.assert_equals(prime(12345),False)
- test.assert_equals(prime(36),False)
- test.assert_equals(prime(36),False)
- test.assert_equals(prime(0), False)
- test.assert_equals(prime(1), False)
- test.assert_equals(prime(2), True)
- test.assert_equals(prime(7), True)
- test.assert_equals(prime(13), True)
- test.assert_equals(prime(97), True)
- test.assert_equals(prime(29), True)
test.assert_equals(prime(115249), True)- test.assert_equals(prime(115249), True)
- test.assert_equals(prime(4), False)
extension Int { var toBinary: Int { return (self < 0 ? -1 : 1) * (Int(String(abs(self), radix: 2)) ?? 0) } }
func binaryConverter(_ input: Int) -> Int {//Your Code Herereturn input- extension Int {
- var toBinary: Int {
- return (self < 0 ? -1 : 1) * (Int(String(abs(self), radix: 2)) ?? 0)
- }
- }
import XCTest // XCTest Spec Example: // TODO: replace with your own tests (TDD), these are just how-to examples to get you started class SolutionTest: XCTestCase { static var allTests = [ ("Test Example", testExample), ] func testExample() { XCTAssertEqual(0.toBinary, 0) XCTAssertEqual(1.toBinary, 1) XCTAssertEqual(5.toBinary, 101) XCTAssertEqual(10.toBinary, 1010) XCTAssertEqual(15.toBinary, 1111) XCTAssertEqual(20.toBinary, 10100) XCTAssertEqual(25.toBinary, 11001) XCTAssertEqual(50.toBinary, 110010) XCTAssertEqual(-50.toBinary, -110010) XCTAssertEqual(12345.toBinary, 11000000111001) } } XCTMain([ testCase(SolutionTest.allTests) ])
- import XCTest
- // XCTest Spec Example:
- // TODO: replace with your own tests (TDD), these are just how-to examples to get you started
- class SolutionTest: XCTestCase {
- static var allTests = [
- ("Test Example", testExample),
- ]
- func testExample() {
let actual = 1XCTAssertEqual(actual, 1)- XCTAssertEqual(0.toBinary, 0)
- XCTAssertEqual(1.toBinary, 1)
- XCTAssertEqual(5.toBinary, 101)
- XCTAssertEqual(10.toBinary, 1010)
- XCTAssertEqual(15.toBinary, 1111)
- XCTAssertEqual(20.toBinary, 10100)
- XCTAssertEqual(25.toBinary, 11001)
- XCTAssertEqual(50.toBinary, 110010)
- XCTAssertEqual(-50.toBinary, -110010)
- XCTAssertEqual(12345.toBinary, 11000000111001)
- }
- }
- XCTMain([
- testCase(SolutionTest.allTests)
- ])
func printRandomNumber(in range: ClosedRange<Int>) { print(Int.random(in: range)) }
import Glibcfor count in 1...20 {print(random() % 100)- func printRandomNumber(in range: ClosedRange<Int>) {
- print(Int.random(in: range))
- }
import XCTest // XCTest Spec Example: // TODO: replace with your own tests (TDD), these are just how-to examples to get you started class SolutionTest: XCTestCase { static var allTests = [ ("Test Example", testExample), ] func testExample() { printRandomNumber(in: 0 ... 100) } } XCTMain([ testCase(SolutionTest.allTests) ])
- import XCTest
- // XCTest Spec Example:
- // TODO: replace with your own tests (TDD), these are just how-to examples to get you started
- class SolutionTest: XCTestCase {
- static var allTests = [
- ("Test Example", testExample),
- ]
- func testExample() {
- printRandomNumber(in: 0 ... 100)
- }
- }
- XCTMain([
- testCase(SolutionTest.allTests)
- ])
- Write a function that takes an unsorted list of unique numbers ranging from 0 to 11.
- Return a list that reverses the numeric differences step-by-step without changing the first number.
- Numbers outside of the given range should be adjusted by modulus to stay within that range.
For example:
[7, 6, 4, 3, 1, 11, 10, 0, 9, 8, 2, 5]
should return
[7, 8, 10, 11, 1, 3, 4, 2, 5, 6, 0, 9]
def invert(tone_row): inversion = [tone_row[0]] for i in range(0, 11): inversion.append((inversion[i] + tone_row[i] - tone_row[i + 1]) % 12) return inversion
def invert(testset):base12 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]invset = [(testset[0])]for s in range(len(testset)-1):interval = testset[s] - testset[s+1]if s == 0:inv_val = testset[s] + intervalif inv_val > 11:inv_val = inv_val - 12else:inv_val += intervalif inv_val > 11:inv_val = inv_val - 12if inv_val < 0:inv_abs = base12[inv_val]else:inv_abs = inv_valinvset.append(inv_abs)return(invset)- def invert(tone_row):
- inversion = [tone_row[0]]
- for i in range(0, 11):
- inversion.append((inversion[i] + tone_row[i] - tone_row[i + 1]) % 12)
- return inversion
test.assert_equals(invert([7, 6, 4, 3, 1, 11, 10, 0, 9, 8, 2, 5]), [7, 8, 10, 11, 1, 3, 4, 2, 5, 6, 0, 9]) test.assert_equals(invert([0, 2, 4, 1, 3, 7, 8, 11, 10, 5, 6, 9]), [0, 10, 8, 11, 9, 5, 4, 1, 2, 7, 6, 3]) test.assert_equals(invert([9, 4, 5, 11, 3, 10, 8, 0, 7, 2, 6, 1]), [9, 2, 1, 7, 3, 8, 10, 6, 11, 4, 0, 5]) test.assert_equals(invert([1, 6, 10, 4, 11, 3, 8, 7, 2, 0, 5, 9]), [1, 8, 4, 10, 3, 11, 6, 7, 0, 2, 9 ,5]) test.assert_equals(invert([8, 4, 6, 2, 7, 10, 11, 1, 9, 5, 3, 0]), [8, 0, 10, 2, 9, 6, 5, 3, 7, 11, 1, 4]) test.assert_equals(invert([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]), [0, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) test.assert_equals(invert([11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]), [11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
# TODO: Replace examples and use TDD development by writing your own tests# These are some of the methods available:# test.expect(boolean, [optional] message)# test.assert_equals(actual, expected, [optional] message)# test.assert_not_equals(actual, expected, [optional] message)# You can use Test.describe and Test.it to write BDD style test groupings- test.assert_equals(invert([7, 6, 4, 3, 1, 11, 10, 0, 9, 8, 2, 5]), [7, 8, 10, 11, 1, 3, 4, 2, 5, 6, 0, 9])
- test.assert_equals(invert([0, 2, 4, 1, 3, 7, 8, 11, 10, 5, 6, 9]), [0, 10, 8, 11, 9, 5, 4, 1, 2, 7, 6, 3])
- test.assert_equals(invert([9, 4, 5, 11, 3, 10, 8, 0, 7, 2, 6, 1]), [9, 2, 1, 7, 3, 8, 10, 6, 11, 4, 0, 5])
- test.assert_equals(invert([1, 6, 10, 4, 11, 3, 8, 7, 2, 0, 5, 9]), [1, 8, 4, 10, 3, 11, 6, 7, 0, 2, 9 ,5])
- test.assert_equals(invert([8, 4, 6, 2, 7, 10, 11, 1, 9, 5, 3, 0]), [8, 0, 10, 2, 9, 6, 5, 3, 7, 11, 1, 4])
- test.assert_equals(invert([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]), [0, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1])
- test.assert_equals(invert([11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]), [11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
#include <stdlib.h> #include <string.h> char *my_strdup_1(const char *str) { const size_t len = strlen(str) + 1; char * const res = malloc(len); if (!res) return (NULL); memcpy(res, str, len); return res; } char *my_strdup_2(const char *str) { const size_t len = strlen(str) + 1; char * const res = malloc(len); if (!res) return (NULL); memcpy(res, str, len); return res; }
- #include <stdlib.h>
- #include <string.h>
- char *my_strdup_1(const char *str) {
const size_t len = strlen(str);char *const res = malloc(len); // <- BUG- const size_t len = strlen(str) + 1;
- char * const res = malloc(len);
- if (!res)
- return (NULL);
- memcpy(res, str, len);
- return res;
- }
- char *my_strdup_2(const char *str) {
const size_t len = strlen(str);char *const res = malloc(len); // <- BUGmemcpy(res, str, len + 1);- const size_t len = strlen(str) + 1;
- char * const res = malloc(len);
- if (!res)
- return (NULL);
- memcpy(res, str, len);
- return res;
- }
#include <criterion/criterion.h> #include <stdlib.h> char *my_strdup_1(const char *str); char *my_strdup_2(const char *str); Test(my_strdup_1, should_work_correctly) { static const char str[] = "Qwerty"; char * const res = my_strdup_1(str); cr_assert_str_eq(res, str); free(res); } Test(my_strdup_2, should_work_correctly) { static const char str[] = "Qwerty"; char *const res = my_strdup_2(str); cr_assert_str_eq(res, str); free(res); }
- #include <criterion/criterion.h>
- #include <stdlib.h>
- char *my_strdup_1(const char *str);
- char *my_strdup_2(const char *str);
- Test(my_strdup_1, should_work_correctly) {
- static const char str[] = "Qwerty";
char *const res = my_strdup_1(str);- char * const res = my_strdup_1(str);
- cr_assert_str_eq(res, str);
- free(res);
- }
- Test(my_strdup_2, should_work_correctly) {
- static const char str[] = "Qwerty";
- char *const res = my_strdup_2(str);
- cr_assert_str_eq(res, str);
- free(res);
- }