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
Code
Diff
  • class Person:
        def __init__(self,name,iq=1):
            self.name=name
            self.iq= 1 if iq == 0 else iq
            
    you = Person("you",0)
    
    print(1/you.iq)
    # hahaha un-rekt!
    • class Person:
    • def __init__(self,name,iq):
    • self.name=name
    • self.iq=iq
    • you=Person("you",0)
    • print(1/you.iq)
    • #ahahaha rekt
    • class Person:
    • def __init__(self,name,iq=1):
    • self.name=name
    • self.iq= 1 if iq == 0 else iq
    • you = Person("you",0)
    • print(1/you.iq)
    • # hahaha un-rekt!
Code
Diff
  • def remove_numbers(s):
        return ''.join([l for l in s if not l.isdigit()])
    • def remove_numbers(string):
    • return ''.join([l for l in string if l not in '1234567890'])
    • def remove_numbers(s):
    • return ''.join([l for l in s if not l.isdigit()])
Strings

Inspired by PyCalc! https://www.codewars.com/kumite/62347c29a786a2004a613da9?sel=62b1afd8ff12495f950a56d8

A interactive terminal program for making your own directory, at a specific path or the current directory the user is in. Feel free to do what you want with the code.

Code
Diff
  • # importing os
    import os
    import sys
    
    class CreateDirectory:
        
        OPTIONS = {1: "Current Path",
               2: "Other Path",
               3: "Cancel"}
        
        def __init__(self, name=None, path_=None):
            self.name = name
            self.path_ = path_
        
        # Function for creating new directory.
        def create_folder(self, folder_name, dirpath):
            # Resets color
            print("\033[0m")
            
            if dirpath != 0:
                print("Checking if path exists...", end="\r")
                if os.path.exists(dirpath):
                    print("\033[32;1mPath found!\033[0m                ")
                    path_ = os.path.join(dirpath, folder_name)
                else:
                    print("\033[31;1mError:\033[0m Invalid path!             ")
                    return False
            else:    
                # creating a variable path to the new folder.
                path_ = os.path.join(os.getcwd(), folder_name)
            
            # check to see if the folder already exists.
            print("Checking if directory already exists...", end="\r")
            if not os.path.exists(path_):
                # if not, make directory
                print(f"\033[32;1mDirectory created successfully at {path_}\033[0m            ")
                os.mkdir(path_)
                return True
            print("\033[31;1mError:\033[0m Directory already exists!             ")
            return False
        
    def display_option_menu(menu_options: dict) -> str:
        # Some code is taken from PyCalc!
        for k, v in menu_options.items():
            print(f'\t({k})-{v.title()}')
    
        while True:
            user_input = input(f'Select option: (1-{len(menu_options)}):\n{chr(129094)} ')
            # Validate input: If not a digit or in menu option, continue to ask user for input.
            if not user_input.isdigit() or int(user_input) not in menu_options:
                print("\033[31;1mError:\033[0m Invalid input!")
                continue
            else:
                # If input is valid; break.
                break
        # Returns user's choice.
        return menu_options.get(int(user_input))
        
    def main():
        # Initializaton of directory creator
        create = CreateDirectory()
        create_options = create.OPTIONS
        while True:
            print("\033[34;4;1m/ / / TELEVISIONIA's Directory Creator / / /\033[0m")
            userinput = display_option_menu(create_options)
            
            match userinput:
                case "Current Path":
                    create.create_folder(input("New Directory name: \033[35m"), 0)
                case "Other Path":
                    create.create_folder(input("New Directory name: \033[35m"), input("\033[0mNew Directory path: \033[35m"))
                case "Cancel":
                    sys.exit()
                case _:
                    return main()
    if __name__ == '__main__':
        main()
    
    • # importing os
    • import os
    • import sys
    • class CreateDirectory:
    • OPTIONS = {1: "Current Path",
    • 2: "Other Path",
    • 3: "Cancel"}
    • def __init__(self, name=None, path_=None):
    • self.name = name
    • self.path_ = path_
    • # Function for creating new directory.
    • def create_folder(self, folder_name, dirpath):
    • # Resets color
    • print("\033[0m")
    • if dirpath != 0:
    • print("Checking if path exists...", end="\r")
    • if os.path.exists(dirpath):
    • print("\033[32;1mPath found!\033[0m ")
    • path_ = os.path.join(dirpath, folder_name)
    • else:
    • print("\033[31;1mError:\033[0m Invalid path! ")
    • return False
    • else:
    • # creating a variable path to the new folder.
    • path_ = os.path.join(os.getcwd(), folder_name)
    • # check to see if the folder already exists.
    • print("Checking if directory already exists...", end="\r")
    • if not os.path.exists(path_):
    • # if not, make directory
    • print(f"\033[32;1mDirectory created successfully at {path_}\033[0m ")
    • os.mkdir(path_)
    • return True
    • print("\033[31;1mError:\033[0m Directory already exists! ")
    • return False
    • def display_option_menu(menu_options: dict) -> str:
    • # Some code is taken from PyCalc!
    • for k, v in menu_options.items():
    • print(f'\t({k})-{v.title()}')
    • def create_folder(folder_name='MyFolder'):
    • # creating a variable path to the new folder.
    • path_ = os.path.join(os.getcwd(), folder_name)
    • # check to see if the folder already exists.
    • if not os.path.exists(folder_name):
    • # if not, make directory
    • os.mkdir(folder_name)
    • return True
    • return False
    • while True:
    • user_input = input(f'Select option: (1-{len(menu_options)}):\n{chr(129094)} ')
    • # Validate input: If not a digit or in menu option, continue to ask user for input.
    • if not user_input.isdigit() or int(user_input) not in menu_options:
    • print("\033[31;1mError:\033[0m Invalid input!")
    • continue
    • else:
    • # If input is valid; break.
    • break
    • # Returns user's choice.
    • return menu_options.get(int(user_input))
    • def main():
    • # Initializaton of directory creator
    • create = CreateDirectory()
    • create_options = create.OPTIONS
    • while True:
    • print("\033[34;4;1m/ / / TELEVISIONIA's Directory Creator / / /\033[0m")
    • userinput = display_option_menu(create_options)
    • match userinput:
    • case "Current Path":
    • create.create_folder(input("New Directory name: \033[35m"), 0)
    • case "Other Path":
    • create.create_folder(input("New Directory name: \033[35m"), input("\033[0mNew Directory path: \033[35m"))
    • case "Cancel":
    • sys.exit()
    • case _:
    • return main()
    • if __name__ == '__main__':
    • main()
Fundamentals
Strings
Code
Diff
  • #include <string.h>
    std::string digest(std::string param) {
        std::string result;
        for (int i = 0; i < param.size() - 1; i++) {
          result += param[i];
          result += ' ';
        }
        result += param[param.size() - 1];
        return result;
    } //Please fix!
    • #include <string.h>
    • std::string digest(std::string param) {
    • std::string result;
    • for (int i = 0; sizeof(param); i++) {
    • for (int i = 0; i < param.size() - 1; i++) {
    • result += param[i];
    • result += ' ';
    • }
    • result += param[param.size() - 1];
    • return result;
    • } //Please fix!
Date Time
Strings
Code
Diff
  • function howManyTimesBetween(string $sentence): string
    {
        if (!preg_match('/^(?<date1>\d{4}-\d{2}-\d{2}) and (?<date2>\d{4}-\d{2}-\d{2})$/', $sentence, $dates)) {
            return 'Your question is strange';
        }
    
        $dates = array_map('date_create', $dates);
        
        if (!($diff = $dates['date1']->diff($dates['date2']))->days) {
          return 'Dates are equals';
        }
    
        $diffStrings = [$diff->format('%y year(s)'), $diff->format('%m month(s)'), $diff->format('%d day(s)')];
        $diffStrings = preg_grep('/^0/', $diffStrings, PREG_GREP_INVERT);
      
        return 'There are '.implode(', ', $diffStrings)." between $sentence";
    }
    • function howManyTimesBetween(string $sentence): string
    • {
    • if (!preg_match('/^(?<date1>\d{4}-\d{2}-\d{2}) and (?<date2>\d{4}-\d{2}-\d{2})$/', $sentence, $dates)) {
    • return 'Your question is strange';
    • }
    • $dates = array_map('date_create', $dates);
    • if ($dates['date1'] == $dates['date2']) {
    • return 'Dates are equals';
    • if (!($diff = $dates['date1']->diff($dates['date2']))->days) {
    • return 'Dates are equals';
    • }
    • $diff = $dates['date1']->diff($dates['date2']);
    • $diffStrings = [$diff->format('%y year(s)'), $diff->format('%m month(s)'), $diff->format('%d day(s)')];
    • $diffStrings = preg_grep('/^0/', $diffStrings, PREG_GREP_INVERT);
    • return 'There are '.implode(', ', $diffStrings)." between $sentence";
    • }
Code
Diff
  • import re
    
    def increment_string(s):
        end_nums = re.match(".+?(\d+)$", s)
        
        if end_nums:
            padded_number = '{:0>{}}'.format(int(end_nums[1])+1, len(end_nums[1]))
            return s[:end_nums.span(1)[0]] + padded_number
        return s + '1'
    • import re
    • def increment_string(s):
    • if s=="": return "1"
    • s = (s, s+"0")[s[-1].isalpha()]
    • s, number = re.compile("(\D+)(\d+)").match(s).groups()
    • return s+'{:0>{}}'.format(int(number)+1, len(number))
    • end_nums = re.match(".+?(\d+)$", s)
    • if end_nums:
    • padded_number = '{:0>{}}'.format(int(end_nums[1])+1, len(end_nums[1]))
    • return s[:end_nums.span(1)[0]] + padded_number
    • return s + '1'

Find the area of a triangle from its width and height.

Code
Diff
  • float AreaOfTriangle(float w, float h) {return (w * h) / 2;} //Get one-lined
    • float AreaOfTriangle(float w, float h) {
    • float A = (w * h) / 2;
    • return A;
    • }
    • float AreaOfTriangle(float w, float h) {return (w * h) / 2;} //Get one-lined