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.
function* blaze_it() { yield 69; yield 420; yield 1337; }; const dark_tech = blaze_it() let a=10; a = dark_tech.next().value; a = dark_tech.next().value; a = dark_tech.next().value; const b = 42; a = 10*b; a= 12; a - Math.sin(Math.PI / 2);
- function* blaze_it() {
- yield 69;
- yield 420;
- yield 1337;
- };
- const dark_tech = blaze_it()
- let a=10;
a = 69;a = 420;- a = dark_tech.next().value;
- a = dark_tech.next().value;
- a = dark_tech.next().value;
- const b = 42;
- a = 10*b;
a= 11;- a= 12;
- a - Math.sin(Math.PI / 2);
def solution(param: list) -> bool: """Returns True if atleast 2 out of 3 booleans are True.""" return sum(p is True for p in param) > 1
- def solution(param: list) -> bool:
- """Returns True if atleast 2 out of 3 booleans are True."""
return sum([1 for p in param if p is True]) >= 2- return sum(p is True for p in param) > 1
package kumite import "time" func CheckWorkHours(dateTime time.Time) bool { return true && dateTime.Weekday() != time.Thursday && dateTime.Weekday() != time.Sunday && dateTime.Hour() >= 8 && dateTime.Hour() < 18 }
- package kumite
- import "time"
func CheckWorkHours(dateTime time.Time) bool {return dateTime.Weekday() != time.Thursday && dateTime.Weekday() != time.Sunday && dateTime.Hour() >= 8 && dateTime.Hour() < 18 }- func CheckWorkHours(dateTime time.Time) bool {
- return true &&
- dateTime.Weekday() != time.Thursday &&
- dateTime.Weekday() != time.Sunday &&
- dateTime.Hour() >= 8 &&
- dateTime.Hour() < 18
- }
Returning zero on edge cases is incorrect, fixed it.
def Calculator(*args): operators = { '+': lambda a, b: a + b, '-': lambda a, b: a - b, '*': lambda a, b: a * b, '/': lambda a, b: a / b if b != 0 else float('inf') } if len(args) != 3 or str(args[0]) not in operators: return float('nan') operator, operand1, operand2 = args return operators[operator](operand1, operand2)
- def Calculator(*args):
- operators = {
- '+': lambda a, b: a + b,
- '-': lambda a, b: a - b,
- '*': lambda a, b: a * b,
'/': lambda a, b: a / b if b != 0 else 0- '/': lambda a, b: a / b if b != 0 else float('inf')
- }
- if len(args) != 3 or str(args[0]) not in operators:
return 0- return float('nan')
- operator, operand1, operand2 = args
- return operators[operator](operand1, operand2)
import codewars_test as test import random from math import isnan inf = float('inf') nan = float('nan') @test.describe("Sample tests") def sample_tests(): test.assert_equals(Calculator("/", 1, 0), inf) test.assert_equals(Calculator("+", 42, 11), 53) test.assert_equals(Calculator("-", 6, 50), -44) test.assert_equals(Calculator("/", 32, 2), 16) test.assert_equals(Calculator("*", 25, 5), 125) test.assert_equals(isnan(Calculator(123, 2)), True) operators = ['+', '-', '*', '/'] @test.describe("Random tests") def random_tests(): for _ in range(2000): operator = random.choice(operators) num1 = random.uniform(0, 1000) num2 = random.uniform(1, 1000) description = f"Operator: {operator}, Num1: {num1}, Num2: {num2}" expected = float(eval(f"{num1}{operator}{num2}")) test.assert_equals(Calculator(operator, num1, num2), expected, description)
- import codewars_test as test
- import random
- from math import isnan
- inf = float('inf')
- nan = float('nan')
- @test.describe("Sample tests")
- def sample_tests():
test.assert_equals(Calculator("/", 1, 0), 0)- test.assert_equals(Calculator("/", 1, 0), inf)
- test.assert_equals(Calculator("+", 42, 11), 53)
- test.assert_equals(Calculator("-", 6, 50), -44)
- test.assert_equals(Calculator("/", 32, 2), 16)
- test.assert_equals(Calculator("*", 25, 5), 125)
test.assert_equals(Calculator(123, 2), 0)- test.assert_equals(isnan(Calculator(123, 2)), True)
- operators = ['+', '-', '*', '/']
- @test.describe("Random tests")
- def random_tests():
- for _ in range(2000):
- operator = random.choice(operators)
- num1 = random.uniform(0, 1000)
- num2 = random.uniform(1, 1000)
- description = f"Operator: {operator}, Num1: {num1}, Num2: {num2}"
- expected = float(eval(f"{num1}{operator}{num2}"))
- test.assert_equals(Calculator(operator, num1, num2), expected, description)
Through experience I found that hardcoding in file names/ destinations/ quantities, etc. always lead to unknown bugs later on.
So I would really prefer having the folder source and destination as a variable/parameter.
import os, shutil class MoveFiles: def __init__(self): self.imageFolder = "folderA" self.images = [img for img in os.listdir(self.imageFolder) if img.endswith(('.png', '.jpg', '.jpeg'))] def move_image_files(self, source = "folderA", destination = "folderB"): for img in self.images: shutil.move(os.path.join(source, img), os.path.join(destination, img))
- import os, shutil
- class MoveFiles:
def __init__(self):self.images = [img for img in os.listdir('folderA') if img.endswith(('.png', '.jpg', '.jpeg'))]- def __init__(self):
- self.imageFolder = "folderA"
- self.images = [img for img in os.listdir(self.imageFolder) if img.endswith(('.png', '.jpg', '.jpeg'))]
def move_image_files(self):- def move_image_files(self, source = "folderA", destination = "folderB"):
- for img in self.images:
shutil.move(os.path.join('folderA', img), os.path.join('folderB', img))- shutil.move(os.path.join(source, img), os.path.join(destination, img))