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.
'''
Morse Code function - remove match case and use dict for better time complexity
'''
def morse_code(msg):
output = ''
morse_dict = {
'a': '.- ',
'b': '-... ',
'c': '-.-. ',
'd': '-.. ',
'e': '. ',
'f': '..-. ',
'g': '--. ',
'h': '.... ',
'i': '.. ',
'j': '.--- ',
'k': '-.- ',
'l': '.-.. ',
'm': '-- ',
'n': '-. ',
'o': '--- ',
'p': '.--. ',
'q': '--.- ',
'r': '.-. ',
's': '... ',
't': '- ',
'u': '..- ',
'v': '...- ',
'w': '.-- ',
'x': '-..- ',
'y': '-.-- ',
'z': '--.. ',
'0': '----- ',
'1': '.---- ',
'2': '..--- ',
'3': '...-- ',
'4': '....- ',
'5': '..... ',
'6': '-.... ',
'7': '--... ',
'8': '---.. ',
'9': '----. ',
'.': '.-.-.- ',
',': '--..-- ',
"'": '.----. ',
'?': '..--.. ',
':': '---... ',
'-': '-....- ',
'/': '-..-. ',
'[': '-.--. ',
'(': '-.--. ',
']': '-.--.- ',
')': '-.--.- ',
'"': '.-..-. ',
'_': '..--.- ',
'=': '-...- ',
'+': '.-.-. ',
'@': '.--.-. ',
'!': '-.-.-- ',
' ': '/ '
}
for letter in msg:
output += output.join([morse_dict.get(letter)])
return output.rstrip()
''' Morse Code function - remove match case and use dict for better time complexity ''' def morse_code(msg): output = '' morse_dict = { 'a': '.- ', 'b': '-... ', 'c': '-.-. ', 'd': '-.. ', 'e': '. ', 'f': '..-. ', 'g': '--. ', 'h': '.... ', 'i': '.. ', 'j': '.--- ', 'k': '-.- ', 'l': '.-.. ', 'm': '-- ', 'n': '-. ', 'o': '--- ', 'p': '.--. ', 'q': '--.- ', 'r': '.-. ', 's': '... ', 't': '- ', 'u': '..- ', 'v': '...- ', 'w': '.-- ', 'x': '-..- ', 'y': '-.-- ', 'z': '--.. ', '0': '----- ', '1': '.---- ', '2': '..--- ', '3': '...-- ', '4': '....- ', '5': '..... ', '6': '-.... ', '7': '--... ', '8': '---.. ', '9': '----. ', '.': '.-.-.- ', ',': '--..-- ', "'": '.----. ', '?': '..--.. ', ':': '---... ', '-': '-....- ', '/': '-..-. ', '[': '-.--. ', '(': '-.--. ', ']': '-.--.- ', ')': '-.--.- ', '"': '.-..-. ', '_': '..--.- ', '=': '-...- ', '+': '.-.-. ', '@': '.--.-. ', '!': '-.-.-- ', ' ': '/ ' } for letter in msg: output += output.join([morse_dict.get(letter)]) return output.rstrip()
- '''
- Morse Code function - remove match case and use dict for better time complexity
- '''
- def morse_code(msg):
dot, dash = '.', '-'space = ' '- output = ''
for letter in msg:match letter:case 'a':output += ''.join([dot, dash, space])case 'b':output += ''.join([dash, dot, dot, dot, space])case 'c':output += ''.join([dash, dot, dash, dot, space])case 'd':output += ''.join([dash, dot, dot, space])case 'e':output += ''.join([dot, space])case 'f':output += ''.join([dot, dot, dash, dot, space])case 'g':output += ''.join([dash, dash, dot, space])case 'h':output += ''.join([dot, dot, dot, dot, space])case 'i':output += ''.join([dot, dot, space])case 'j':output += ''.join([dot, dash, dash, dash, space])case 'k':output += ''.join([dash, dot, dash, space])case 'l':output += ''.join([dot, dash, dot, dot, space])case 'm':output += ''.join([dash, dash, space])case 'n':output += ''.join([dash, dot, space])case 'o':output += ''.join([dash, dash, dash, space])case 'p':output += ''.join([dot, dash, dash, dot, space])case 'q':output += ''.join([dash, dash, dot, dash, space])case 'r':output += ''.join([dot, dash, dot, space])case 's':output += ''.join([dot, dot, dot, space])case 't':output += ''.join([dash, space])case 'u':output += ''.join([dot, dot, dash, space])case 'v':output += ''.join([dot, dot, dot, dash, space])case 'w':output += ''.join([dot, dash, dash, space])case 'x':output += ''.join([dash, dot, dot, dash, space])case 'y':output += ''.join([dash, dot, dash, dash, space])case 'z':output += ''.join([dash,dash, dot, dot, space])case '0':output += ''.join([dash, dash, dash, dash, dash, space])case '1':output += ''.join([dot, dash, dash, dash, dash, space])case '2':output += ''.join([dot, dot, dash, dash, dash, space])case '3':output += ''.join([dot, dot, dot, dash, dash, space])case '4':output += ''.join([dot, dot, dot, dot, dash, space])case '5':output += ''.join([dot, dot, dot, dot, dot, space])case '6':output += ''.join([dash, dot, dot, dot, dot, space])case '7':output += ''.join([dash, dash, dot, dot, dot, space])case '8':output += ''.join([dash, dash, dash, dot, dot, space])case '9':output += ''.join([dash, dash, dash, dash, dot, space])case '.':output += ''.join([dot, dash, dot, dash, dot, dash,space])case ',':output += ''.join([dash, dash, dot, dot, dash, dash])case "'":output += ''.join([dot, dash, dash, dash, dash, dot])case '?':output += ''.join([dot, dot, dash, dash, dot, dot])case ':':output += ''.join([dash, dash, dash, dot, dot, dot])case '-':output += ''.join([dash, dot, dot, dot, dot, dash,space])case '/':output += ''.join([dash, dot, dot, dash, dot, space])case '[':output += ''.join([dash, dot, dash, dash, dot,space])case '(':output += ''.join([dash, dot, dash, dash, dot,space])case ']':output += ''.join([dash, dot, dash, dash, dot, dash,space])case ')':output += ''.join([dash, dot, dash, dash, dot, dash,space])case '"':output += ''.join([dot, dash, dot, dot, dash, dot])case '_':output += ''.join([dot, dot, dash, dash, dot, dash])case '=':output += ''.join([dash, dot, dot, dot, dash, space])case '+':output += ''.join([dot, dash, dot, dash, dot, space])case '@':output += ''.join([dot, dash, dash, dot, dash, dot, space])case '!':output += ''.join([dash, dot, dash, dot, dash, dash])case ' ':output += '/ '- morse_dict = {
- 'a': '.- ',
- 'b': '-... ',
- 'c': '-.-. ',
- 'd': '-.. ',
- 'e': '. ',
- 'f': '..-. ',
- 'g': '--. ',
- 'h': '.... ',
- 'i': '.. ',
- 'j': '.--- ',
- 'k': '-.- ',
- 'l': '.-.. ',
- 'm': '-- ',
- 'n': '-. ',
- 'o': '--- ',
- 'p': '.--. ',
- 'q': '--.- ',
- 'r': '.-. ',
- 's': '... ',
- 't': '- ',
- 'u': '..- ',
- 'v': '...- ',
- 'w': '.-- ',
- 'x': '-..- ',
- 'y': '-.-- ',
- 'z': '--.. ',
- '0': '----- ',
- '1': '.---- ',
- '2': '..--- ',
- '3': '...-- ',
- '4': '....- ',
- '5': '..... ',
- '6': '-.... ',
- '7': '--... ',
- '8': '---.. ',
- '9': '----. ',
- '.': '.-.-.- ',
- ',': '--..-- ',
- "'": '.----. ',
- '?': '..--.. ',
- ':': '---... ',
- '-': '-....- ',
- '/': '-..-. ',
- '[': '-.--. ',
- '(': '-.--. ',
- ']': '-.--.- ',
- ')': '-.--.- ',
- '"': '.-..-. ',
- '_': '..--.- ',
- '=': '-...- ',
- '+': '.-.-. ',
- '@': '.--.-. ',
- '!': '-.-.-- ',
- ' ': '/ '
- }
- for letter in msg:
- output += output.join([morse_dict.get(letter)])
- return output.rstrip()
Changed the function into a class.
class KilogramsToGrams: gram_conversion = 1000 def __init__(self, kilograms): self.kilograms = kilograms def convert(self): return self.kilograms * self.gram_conversion
def kilogramsToGrams(kilograms=1):return kilograms * 1000- class KilogramsToGrams:
- gram_conversion = 1000
- def __init__(self, kilograms):
- self.kilograms = kilograms
- def convert(self):
- return self.kilograms * self.gram_conversion
import codewars_test as test from solution import KilogramsToGrams GRAM_CONVERSION = 1000 @test.describe("Example") def test_group(): @test.it("test case") def test_case(): samples = (0, 1, 3.1415926535898, 13, 101, 333, 776, 666, 3121534312) for n in samples: test.assert_equals(KilogramsToGrams(n).convert(), n * GRAM_CONVERSION)
# 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)- import codewars_test as test
- from solution import KilogramsToGrams
- GRAM_CONVERSION = 1000
# You can use Test.describe and Test.it to write BDD style test groupingstest.assert_equals(kilogramsToGrams(1), 1000)test.assert_equals(kilogramsToGrams(1.365), 1365)kilograms = 0.126grams = 126test.assert_equals(kilograms*kilogramsToGrams(), grams)- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- samples = (0, 1, 3.1415926535898, 13, 101, 333, 776, 666, 3121534312)
- for n in samples:
- test.assert_equals(KilogramsToGrams(n).convert(), n * GRAM_CONVERSION)
section .text global is_square ; C-style declaration: ``_Bool is_square();`` is_square: CVTSI2SS xmm0, rdi ; sqrt takes a ``double`` as its argument, so converting rdi to ``double`` first SQRTSS xmm0, xmm0 ; now, XMM0 = sqrt(XMM0 CVTSS2SI rax, xmm0 ; RAX = (int) XMM0 MUL rax ; RAX *= RAX XOR rax, rdi ; if this XOR evaluates to 0, then RAX == RDI SETZ al ; in which case you set the lower 8 bits of AX to 00000001, i.e. "true" RET ; return to the caller
- section .text
- global is_square ; C-style declaration: ``_Bool is_square();``
extern sqrt ; C-style declaration: ``double sqrt(double);``- is_square:
cvtsi2sd xmm0, rdi ; sqrt takes a ``double`` as its argument, so converting rdi to ``double`` firstcall sqrt ; now, XMM0 = sqrt(XMM0)cvtsd2si rax, xmm0 ; RAX = (int) XMM0mul rax ; RAX *= RAXxor rax, rdi ; if this XOR evaluates to 0, then RAX == RDIsetz al ; in which case you set the lower 8 bits of AX to 00000001, i.e. "true"ret ; return to the caller- CVTSI2SS xmm0, rdi ; sqrt takes a ``double`` as its argument, so converting rdi to ``double`` first
- SQRTSS xmm0, xmm0 ; now, XMM0 = sqrt(XMM0
- CVTSS2SI rax, xmm0 ; RAX = (int) XMM0
- MUL rax ; RAX *= RAX
- XOR rax, rdi ; if this XOR evaluates to 0, then RAX == RDI
- SETZ al ; in which case you set the lower 8 bits of AX to 00000001, i.e. "true"
- RET ; return to the caller
Patriotic task #776: Convert Javascript to Python
def determine_brand(brand): d = { "McDonald's": "Poison food", "Tinkoff": "T-Bank", "LeroyMerlin": "LemanaPro", "YouTube": "Pr0nHub", "Dollar": "Bitcoin" } return d.get(brand, None)
// Демироваимпортозамещение = (брэнд) => {const брэнды = {МакДоналдс: "Вкусно и точка",Тинькофф: "Т-Банк",ЛеруаМерлен: "ЛеманаПро",YouTube: "Rutube",Доллар: "Рубль"};return брэнды[брэнд] ? брэнды[брэнд] : 'брэнд не распознан';}- def determine_brand(brand):
- d = {
- "McDonald's": "Poison food",
- "Tinkoff": "T-Bank",
- "LeroyMerlin": "LemanaPro",
- "YouTube": "Pr0nHub",
- "Dollar": "Bitcoin"
- }
- return d.get(brand, None)
import codewars_test as test from solution import determine_brand # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): samples = (("McDonald's", "Poison food"), ("Tinkoff", "T-Bank"), ("LeroyMerlin", "LemanaPro"), ("YouTube", "Pr0nHub"), ("Dollar", "Bitcoin") , ("Codewars", None) ) for sample in samples: value, expected = sample[0], sample[1] test.assert_equals(determine_brand(value),expected)
const chai = require("chai");const assert = chai.assert;- import codewars_test as test
- from solution import determine_brand
describe("Solution", function() {it("тестирование патриотической функции на правильность вычислений", function() {assert.strictEqual(импортозамещение("YouTube"), "Rutube");assert.strictEqual(импортозамещение("Intel"), "брэнд не распознан");});it("тестирование патриотической функции на количество английских слов", function() {let f=импортозамещение.toString();let arr1 = f.match(/[a-z]+/gi)//let arr2 = f.match(/[а-я]+/gi)let r=arr1.length>4assert.strictEqual(r, false);});});- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- samples = (("McDonald's", "Poison food"),
- ("Tinkoff", "T-Bank"),
- ("LeroyMerlin", "LemanaPro"),
- ("YouTube", "Pr0nHub"),
- ("Dollar", "Bitcoin") ,
- ("Codewars", None)
- )
- for sample in samples:
- value, expected = sample[0], sample[1]
- test.assert_equals(determine_brand(value),expected)
Converted to Python
def bool_to_word(param): return {True: "Yes", False: "No"}[param]
#include<stdbool.h>const char *bool_to_word (bool value){return value ? "Yes" : "No";}- def bool_to_word(param):
- return {True: "Yes", False: "No"}[param]
import codewars_test as test from solution import bool_to_word # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(bool_to_word(True), "Yes") test.assert_equals(bool_to_word(False), "No")
#include <stdbool.h>#include <criterion/criterion.h>- import codewars_test as test
- from solution import bool_to_word
extern const char *bool_to_word (bool value);static void do_test (bool b, const char *expected){const char *actual = bool_to_word(b);cr_assert_str_eq(actual, expected,"for %s, expected \"%s\", but got \"%s\"",b ? "true" : "false", expected, actual);}Test (Bool_to_word, sample_tests){do_test(true, "Yes");do_test(false, "No");}- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- test.assert_equals(bool_to_word(True), "Yes")
- test.assert_equals(bool_to_word(False), "No")
// Демирова когоБольше = (...группа) => { const мальчики = группа.reduce((счет, пол) => счет + (пол === 1 ? 1 : 0), 0); const девочки = группа.reduce((счет, пол) => счет + (пол === -1 ? 1 : 0), 0); return мальчики > девочки ? 'Девочек на 1 меньше' : девочки > мальчики ? 'Девочек на 1 больше' : 'Девочек и мальчиков равное количество'; }
- // Демирова
- когоБольше = (...группа) => {
- const мальчики = группа.reduce((счет, пол) => счет + (пол === 1 ? 1 : 0), 0);
- const девочки = группа.reduce((счет, пол) => счет + (пол === -1 ? 1 : 0), 0);
- return мальчики > девочки ? 'Девочек на 1 меньше' : девочки > мальчики ? 'Девочек на 1 больше' : 'Девочек и мальчиков равное количество';
- }