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 Solution:
        def __init__(self, data):
            self.data = data
            self.filename = 'kumite776.txt'
            
        def write_to_file(self):
            with open(self.filename, 'w') as fo:
                fo.write(self.data)
    
        
    • class Solution:
    • def __init__(self, data):
    • self.data = data
    • self.filename = 'kumite776.txt'
    • def write_to_file(self):
    • pass
    • with open(self.filename, 'w') as fo:
    • fo.write(self.data)

This method uses the counting sort algorithm. The overall time complexity of this algorithm is O(m+n) where m is the number of elements in the input array and n is the range of input.

Code
Diff
  • def greatest(lst):
        output = ''
        c = [0] * (max(lst) + 1)
        for i in lst:
            c[i] += 1
        s = []
        for i in reversed(range(len(c))):
            while c[i] != 0:
                c[i] -= 1
                s.append(i)
        for n in s:
            output += f'{n}'
        return int(output)
    • def greatest(lst):
    • return int(''.join(map(str, sorted(lst)[::-1])))
    • output = ''
    • c = [0] * (max(lst) + 1)
    • for i in lst:
    • c[i] += 1
    • s = []
    • for i in reversed(range(len(c))):
    • while c[i] != 0:
    • c[i] -= 1
    • s.append(i)
    • for n in s:
    • output += f'{n}'
    • return int(output)
Fundamentals
Arrays

I dont't like nesting more than 2 times, so I inverted the condition.
Also, extracting the generator is more idiomatic way to convert it to list + it looks prettier for me.

Code
Diff
  • def flatten_list(lst):
        def flatten(l):
            for i in l:
                if not isinstance(i, (list, tuple)):
                    yield i
                    continue
                for j in flatten_list(i):
                    yield j
    
        return [*flatten(lst)]
    • def flatten_list(lst):
    • def flatten(l):
    • for i in l:
    • if isinstance(i, (list, tuple)):
    • for j in flatten_list(i):
    • yield j
    • else:
    • if not isinstance(i, (list, tuple)):
    • yield i
    • return list(flatten(lst))
    • continue
    • for j in flatten_list(i):
    • yield j
    • return [*flatten(lst)]
Code
Diff
  • def knight_move3d(pos=(0, 0, 0)) -> bool:
        if pos == (0, 0, 0):
            return True
        return [*sorted(map(abs, pos))] == [0, 1, 2]
    • def knight_move3d(pos=(0, 0, 0)) -> bool:
    • if pos == (0, 0, 0):
    • return True
    • if max(pos, key=abs) > 2 or 0 not in pos:
    • return False
    • return sum(map(abs, pos)) == 3
    • return [*sorted(map(abs, pos))] == [0, 1, 2]
Code
Diff
  • import random
    
    def elf_hub(nauthy, nice):
        x = random.randint(1, 3)
        
        if nice and not nauthy:
            return "You've been nice!" + '🎁' * x
        elif not nice and nauthy:
            return "You've been naughty!" + '🔥' * x
        elif nauthy and nice:
            return "Youve been naughty and nice" + '🎅' + x * 'Ho'
        
        return None
    
    • import random
    • def elf_hub(naughty, nice):
    • output = ''
    • def elf_hub(nauthy, nice):
    • x = random.randint(1, 3)
    • def giftwrap():
    • nonlocal x
    • nonlocal output
    • if nice:
    • output = "You've been nice!" + '🎁' * x
    • return output
    • def heat_coal():
    • nonlocal x
    • nonlocal output
    • output = "You've been naughty!" + '🔥' * x
    • if naughty:
    • return output
    • def santa():
    • nonlocal x
    • nonlocal output
    • if nice and not nauthy:
    • return "You've been nice!" + '🎁' * x
    • elif not nice and nauthy:
    • return "You've been naughty!" + '🔥' * x
    • elif nauthy and nice:
    • return "Youve been naughty and nice" + '🎅' + x * 'Ho'
    • if nice and not naughty:
    • return giftwrap()
    • elif not nice and naughty:
    • return heat_coal()
    • elif naughty and nice:
    • return santa()
    • else:
    • return None
    • return None
Code
Diff
  • import re
    
    
    def simon_says(action: str):
        pattern = re.compile(r'^\b(Simon says,?\s*)(.*)', re.IGNORECASE)
        match = pattern.search(action)
        if match and len(match.group(1)) in [11,12]:
            extracted_text = match.group(2)
            return extracted_text.strip('"')
        else:
            return 'You didn\'t say, "Simon says"!'
    • def simon_says(action: str)-> str:
    • pass
    • import re
    • def simon_says(action: str):
    • pattern = re.compile(r'^\b(Simon says,?\s*)(.*)', re.IGNORECASE)
    • match = pattern.search(action)
    • if match and len(match.group(1)) in [11,12]:
    • extracted_text = match.group(2)
    • return extracted_text.strip('"')
    • else:
    • return 'You didn\'t say, "Simon says"!'

where were u wen codewar die?

made a full change to allow for all types of input for activity, location, food_source

Code
Diff
  • from typing import Any
    
    def where_were_you_when_codewars_died(activity:Any, location:Any, food_source:Any):
        db = Connection()
        record = f"I was at {location} consuming {food_source} when {activity} died."
        return db.add_record(record)
    
    • from typing import Any
    • def where_were_you_when_codewars_died(activity:str, location:str, food_source:Any):
    • def where_were_you_when_codewars_died(activity:Any, location:Any, food_source:Any):
    • db = Connection()
    • record = f"I was at {location} consuming {food_source} when {activity} died."
    • return db.add_record(record)