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

We want to know wether there are more words which have a greater alphabetic value than numeric value, to do this we will sum the values of the letters and we will have to compare them with the result of the multiplication of the numbers.
If there are more words that have a greater alphabetic value we will return -1, if it's all the way around and there are more words which multiplication of their numbers is greater we will return 1 and if there are the same amount of words on both ends we will return 0.
To make this clear here are some examples:

Code
Diff
  • class UserInfo:
        def __init__(self, *args):
            self.first_name, self.last_name, self.age, self.job, self.hobbies = args
        
        def __getattr__(self, name):
            match name:
                case "full_name":
                    return f'{self.first_name} {self.last_name}'
                case "email":
                    return f'{self.first_name[0]}{self.last_name}@matrix.com'
    • from dataclasses import dataclass, field
    • @dataclass
    • class UserInfo:
    • first_name: str
    • last_name: str
    • age: int
    • job: str
    • hobbies: list
    • @property
    • def full_name(self):
    • return f'{self.first_name} {self.last_name}'
    • @property
    • def email(self):
    • return f'{self.first_name[0]}{self.last_name}@matrix.com'
    • def __init__(self, *args):
    • self.first_name, self.last_name, self.age, self.job, self.hobbies = args
    • def __getattr__(self, name):
    • match name:
    • case "full_name":
    • return f'{self.first_name} {self.last_name}'
    • case "email":
    • return f'{self.first_name[0]}{self.last_name}@matrix.com'

One new test.

Code
Diff
  • class TemperatureConverter:
        def __init__(self, temp):
            self.temp = temp
            
        def fahrenheit_to_celsius(self):
            return round((self.temp - 32) * 5 / 9, 2)
        
        def celsius_to_fahrenheit(self):
            return round((self.temp * 9 / 5) + 32, 2)
    • class TemperatureConverter:
    • def __init__(self, temp):
    • self.temp = temp
    • def fahrenheit_to_celsius(self):
    • pass
    • return round((self.temp - 32) * 5 / 9, 2)
    • def celsius_to_fahrenheit(self):
    • pass
    • return round((self.temp * 9 / 5) + 32, 2)
Code
Diff
  • class KumiteFoo:
        def __init__(self, p):
            self.p = p
            self.condition = 'Yes' if len(self.p) and not sum(map(ord, self.p.lower())) % 324 else 'No'
    
        def solution(self):
            return self.condition
    • class KumiteFoo:
    • def __init__(self, p):
    • self.p = p
    • self.condition = 'Yes' if len(self.p) and not sum(map(ord, self.p.lower())) % 324 else 'No'
    • def solution(self):
    • return 'Yes' if len(self.p) and not sum(map(ord, self.p.lower()))%324 else 'No'
    • return self.condition
Debugging
Image Processing
Code
Diff
  • import os, shutil
    
    class MoveFiles:
        def __init__(self):    
            self.images = [img for img in os.listdir('folderA') if img.endswith(('.png', '.jpg', '.jpeg'))]
    
        def move_image_files(self):
            for img in self.images:
                shutil.move(os.path.join('folderA', img), os.path.join('folderB', img))
    
    • import shutil
    • import os
    • import os, shutil
    • class MoveFiles:
    • def __init__(self):
    • self.images = [img for img in os.listdir('folderA') if img.endswith(('.png', '.jpg', '.jpeg'))]
    • def move_image_files(self):
    • for img in self.images:
    • new_path = os.path.join('folderB', img)
    • shutil.move(os.path.join('folderA', img), new_path)
    • shutil.move(os.path.join('folderA', img), os.path.join('folderB', img))