Start a new Kumite
AllAgda (Beta)BF (Beta)CCFML (Beta)ClojureCOBOL (Beta)CoffeeScriptCommonLisp (Beta)CoqC++CrystalC#D (Beta)DartElixirElm (Beta)Erlang (Beta)Factor (Beta)Forth (Beta)Fortran (Beta)F#GoGroovyHaskellHaxe (Beta)Idris (Beta)JavaJavaScriptJulia (Beta)Kotlinλ Calculus (Beta)LeanLuaNASMNim (Beta)Objective-C (Beta)OCaml (Beta)Pascal (Beta)Perl (Beta)PHPPowerShell (Beta)Prolog (Beta)PureScript (Beta)PythonR (Beta)RacketRaku (Beta)Reason (Beta)RISC-V (Beta)RubyRustScalaShellSolidity (Beta)SQLSwiftTypeScriptVB (Beta)
Show only mine

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.

Ad
Ad

'''
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()
Code
Diff
  • '''
    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.

Code
Diff
  • 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
Fundamentals
Mathematics
Code
Diff
  • 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`` first
    • call sqrt ; now, XMM0 = sqrt(XMM0)
    • cvtsd2si 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
    • 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

Code
Diff
  • 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)

Converted to Python

Code
Diff
  • 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]
Code
Diff
  • // Патриотическая работа №2 Борискин Даниил
    _ = (_1,_2) => (_2 == _1)?_1:_2+_(_1,_2-1)
    
    • // Патриотическая работа №2
    • // Патриотическая работа №2 Борискин Даниил
    • _ = (_1,_2) => (_2 == _1)?_1:_2+_(_1,_2-1)
Code
Diff
  • // Демирова
    когоБольше = (...группа) => {
        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 больше' : 'Девочек и мальчиков равное количество';
    • }