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.
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.
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)
import codewars_test as test from solution import greatest @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(greatest([1,2,3,5,5,3,9,0,3,4,3]), 95543333210) test.assert_equals(greatest([6,6,6,7,7,0]), 776660) test.assert_equals(greatest([1, 5, 4, 3, 9, 2, 0, 1, 6, 4, 9, 0, 7, 6, 1]), 997665443211100)
- import codewars_test as test
# TODO Write testsimport solution # or from solution import example- from solution import greatest
# test.assert_equals(actual, expected, [optional] message)- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- test.assert_equals(greatest([1,2,3,5,5,3,9,0,3,4,3]), 95543333210)
test.assert_equals(greatest([6,6,6,7,7,0]), 776660)- test.assert_equals(greatest([6,6,6,7,7,0]), 776660)
- test.assert_equals(greatest([1, 5, 4, 3, 9, 2, 0, 1, 6, 4, 9, 0, 7, 6, 1]), 997665443211100)
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.
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 jelse:- if not isinstance(i, (list, tuple)):
- yield i
return list(flatten(lst))- continue
- for j in flatten_list(i):
- yield j
- return [*flatten(lst)]
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 Falsereturn sum(map(abs, pos)) == 3- return [*sorted(map(abs, pos))] == [0, 1, 2]
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 xnonlocal outputif nice:output = "You've been nice!" + '🎁' * xreturn outputdef heat_coal():nonlocal xnonlocal outputoutput = "You've been naughty!" + '🔥' * xif naughty:return outputdef santa():nonlocal xnonlocal 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
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
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)
import random import codewars_test as test from solution import Connection, where_were_you_when_codewars_died # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(where_were_you_when_codewars_died(activity='codewars', location='127.0.0.1', food_source='coffee'), 'I was at 127.0.0.1 consuming coffee when codewars died.') test.assert_equals(where_were_you_when_codewars_died(activity='codewars', location='Phantom Forces', food_source='pizza'), 'I was at Phantom Forces consuming pizza when codewars died.') test.assert_equals(where_were_you_when_codewars_died(activity='codewars', location='Phantom Forces', food_source=9), 'I was at Phantom Forces consuming 9 when codewars died.') @test.it("random cases") def randomcases(): locations = ["House", "Bar", "88.131.626.98:25565", random.randint(1,10), "Haus", "There", "Their", "They're", None] for i in range(100): findtester = random.randint(1, 1000000) location = random.choice(locations) test.assert_equals(where_were_you_when_codewars_died(activity='codewars', location=location, food_source=findtester), f'I was at {location} consuming {findtester} when codewars died.')
- import random
- import codewars_test as test
- from solution import Connection, where_were_you_when_codewars_died
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- test.assert_equals(where_were_you_when_codewars_died(activity='codewars', location='127.0.0.1', food_source='coffee'), 'I was at 127.0.0.1 consuming coffee when codewars died.')
- test.assert_equals(where_were_you_when_codewars_died(activity='codewars', location='Phantom Forces', food_source='pizza'), 'I was at Phantom Forces consuming pizza when codewars died.')
- test.assert_equals(where_were_you_when_codewars_died(activity='codewars', location='Phantom Forces', food_source=9), 'I was at Phantom Forces consuming 9 when codewars died.')
- @test.it("random cases")
- def randomcases():
- locations = ["House", "Bar", "88.131.626.98:25565", random.randint(1,10), "Haus", "There", "Their", "They're", None]
- for i in range(100):
- findtester = random.randint(1, 1000000)
test.assert_equals(where_were_you_when_codewars_died(activity='codewars', location="Your Mothers", food_source=findtester), f'I was at Your Mothers consuming {str(findtester)} when codewars died.')- location = random.choice(locations)
- test.assert_equals(where_were_you_when_codewars_died(activity='codewars', location=location, food_source=findtester), f'I was at {location} consuming {findtester} when codewars died.')