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.
extern malloc global reverse_string reverse_string: mov rcx, -1 rs_continue: inc rcx cmp byte [rdi+rcx], 0 jnz rs_continue push rcx push rdi call malloc pop rdi pop rbx mov rcx, 0 rs_copy: dec rbx mov dl, [rdi+rbx] mov [rax+rcx], dl inc rcx cmp rbx, 0 jnz rs_copy mov byte [rax+rcx], 0 ret
#include <stdlib.h>#include <string.h>char* reverse_string(const char* word) {if (!word) {return NULL;}- extern malloc
- global reverse_string
- reverse_string:
- mov rcx, -1
- rs_continue:
- inc rcx
- cmp byte [rdi+rcx], 0
- jnz rs_continue
- push rcx
- push rdi
- call malloc
- pop rdi
- pop rbx
- mov rcx, 0
size_t len = strlen(word);char* res = (char*)malloc(len + 1);if (!res) {return NULL;}for (size_t i = 0; i < len; ++i) {res[i] = word[len - 1 - i];}res[len] = '\0';return res;}- rs_copy:
- dec rbx
- mov dl, [rdi+rbx]
- mov [rax+rcx], dl
- inc rcx
- cmp rbx, 0
- jnz rs_copy
- mov byte [rax+rcx], 0
- ret
#include <criterion/criterion.h> #include <stdio.h> char *reverse_string(const char *word); void tester(const char *word, const char *expected) { char *res = reverse_string(word); cr_assert_str_eq(res, expected); free(res); } Test(Sample_Tests, Valid_Input_Test) { tester("monkey", "yeknom"); tester("home", "emoh"); tester("pneumonoultramicroscopicsilicovolcanoconiosis", "sisoinoconaclovociliscipocsorcimartluonomuenp"); }
- #include <criterion/criterion.h>
- #include <stdio.h>
- char *reverse_string(const char *word);
- void tester(const char *word, const char *expected)
- {
- char *res = reverse_string(word);
- cr_assert_str_eq(res, expected);
- free(res);
- }
- Test(Sample_Tests, Valid_Input_Test)
- {
- tester("monkey", "yeknom");
- tester("home", "emoh");
- tester("pneumonoultramicroscopicsilicovolcanoconiosis", "sisoinoconaclovociliscipocsorcimartluonomuenp");
- }
import codewars_test as test # TODO Write tests import solution # or from solution import example @test.it("Basic tests") def basic_tests(): valid = ["⚀", "⚁", "⚂", "⚃", "⚄", "⚅"] # roll 100 times for _ in range(100): result = a() test.expect(result in valid, f"Got {result} but expected one of {valid}")
- import codewars_test as test
- # TODO Write tests
- import solution # or from solution import example
- @test.it("Basic tests")
- def basic_tests():
- valid = ["⚀", "⚁", "⚂", "⚃", "⚄", "⚅"]
- # roll 100 times
- for _ in range(100):
result = d()- result = a()
- test.expect(result in valid, f"Got {result} but expected one of {valid}")
-- Moonscript! is_perfect_square: => @ ^ 0.5 % 1 == 0
is_perfect_square = lambda n: not n**0.5 % 1- -- Moonscript!
- is_perfect_square: => @ ^ 0.5 % 1 == 0
--[=[ import is_perfect_square from require "moon_solution" it "Is a Perfect Square for Ints", -> for x in *{ 0, 1, 4, 9 } assert.is.true is_perfect_square x for x in *{ 2, 3, 5, 6, 7, 8 } assert.is.false is_perfect_square x --]=] require "setup"
for x in [0, 1, 4, 9]:Test.assert_equals(is_perfect_square(x), True)- --[=[
- import is_perfect_square from require "moon_solution"
for x in [2, 3, 5, 6, 7, 8]:Test.assert_equals(is_perfect_square(x), False)- it "Is a Perfect Square for Ints", ->
- for x in *{ 0, 1, 4, 9 }
- assert.is.true is_perfect_square x
- for x in *{ 2, 3, 5, 6, 7, 8 }
- assert.is.false is_perfect_square x
- --]=] require "setup"
#include <stddef.h> #include <stdlib.h> int * twin_sum_solutions (int *input, size_t input_len, size_t *output_len) { if (input_len < 2) { *output_len = 0; return NULL; } size_t max_possible_twins = input_len / 2; int *result = malloc (max_possible_twins * sizeof (int)); *output_len = 0; for (size_t i = 0; i < input_len - 1; /* i incremented below */) { if (input[i] == input[i + 1]) { if (result) { // check needed if malloc can fail and return null result[*output_len] = input[i] * 2; (*output_len)++; } i += 2; } else { i++; } } int *final_result = realloc (result, *output_len * sizeof (int)); // handle case where realloc fails when shrinking (unlikely) // if (!final_result && *output_len > 0) { // free(result); // free original block // *output_len = 0; // indicate failure or handle appropriately // return NULL; // } // if *output_len is 0, realloc should return NULL or a unique ptr. // if *output_len > 0 and final_result is NULL, it's an error. // the competitive programming context often assumes malloc/realloc succeed. // if realloc fails when *output_len > 0, the original 'result' pointer is still valid // but points to the oversized block. returning 'result' might be an option // but doesn't match the expectation of a tightly sized block. // returning null on failure is safer if the caller checks. // simplified return for typical cp context: if (!final_result && *output_len > 0) { // technically indicates an error, but might pass if caller doesn't check // and *output_len is used correctly. freeing original `result` might be needed. // let's stick to returning what realloc gave, which is NULL in this error case. // the original `result` memory is leaked if we just return NULL here without freeing. // however, if realloc returns NULL for size 0, that's expected. // Let's assume realloc works for non-zero or returns NULL for zero size correctly. return NULL; // return null if realloc failed for non-zero size request } return final_result; // returns NULL if *output_len is 0 and realloc(ptr, 0) returns NULL }
- #include <stddef.h>
- #include <stdlib.h>
- int *
- twin_sum_solutions (int *input, size_t input_len, size_t *output_len)
- {
int *res = malloc (input_len * sizeof (int));for (size_t i = *output_len = 0; i < input_len - 1; i++)if (input[i] == input[i + 1])res[(*output_len)++] = input[i] * 2, i++;return realloc (res, *output_len * sizeof (int));- if (input_len < 2) {
- *output_len = 0;
- return NULL;
- }
- size_t max_possible_twins = input_len / 2;
- int *result = malloc (max_possible_twins * sizeof (int));
- *output_len = 0;
- for (size_t i = 0; i < input_len - 1; /* i incremented below */)
- {
- if (input[i] == input[i + 1])
- {
- if (result) { // check needed if malloc can fail and return null
- result[*output_len] = input[i] * 2;
- (*output_len)++;
- }
- i += 2;
- }
- else
- {
- i++;
- }
- }
- int *final_result = realloc (result, *output_len * sizeof (int));
- // handle case where realloc fails when shrinking (unlikely)
- // if (!final_result && *output_len > 0) {
- // free(result); // free original block
- // *output_len = 0; // indicate failure or handle appropriately
- // return NULL;
- // }
- // if *output_len is 0, realloc should return NULL or a unique ptr.
- // if *output_len > 0 and final_result is NULL, it's an error.
- // the competitive programming context often assumes malloc/realloc succeed.
- // if realloc fails when *output_len > 0, the original 'result' pointer is still valid
- // but points to the oversized block. returning 'result' might be an option
- // but doesn't match the expectation of a tightly sized block.
- // returning null on failure is safer if the caller checks.
- // simplified return for typical cp context:
- if (!final_result && *output_len > 0) {
- // technically indicates an error, but might pass if caller doesn't check
- // and *output_len is used correctly. freeing original `result` might be needed.
- // let's stick to returning what realloc gave, which is NULL in this error case.
- // the original `result` memory is leaked if we just return NULL here without freeing.
- // however, if realloc returns NULL for size 0, that's expected.
- // Let's assume realloc works for non-zero or returns NULL for zero size correctly.
- return NULL; // return null if realloc failed for non-zero size request
- }
- return final_result; // returns NULL if *output_len is 0 and realloc(ptr, 0) returns NULL
- }