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.
dumbRockPaperScissors=lambda a,b:('Draw','Player 1 wins','Player 2 wins')['RPS'.find(a[0])-'RPS'.find(b[0])] def rps (p1,p2): retval= { 'R':{'R': 0, 'S':-1, "P": 1}, 'S':{'R': 1, 'S': 0, 'P':-1}, 'P':{'R':-1, 'S': 1, 'P':0} } return retval[p1][p2]
dumbRockPaperScissors=lambda a,b:('Draw','Player 1 wins','Player 2 wins')['RPS'.find(a[0])-'RPS'.find(b[0])]- dumbRockPaperScissors=lambda a,b:('Draw','Player 1 wins','Player 2 wins')['RPS'.find(a[0])-'RPS'.find(b[0])]
- def rps (p1,p2):
- retval= {
- 'R':{'R': 0, 'S':-1, "P": 1},
- 'S':{'R': 1, 'S': 0, 'P':-1},
- 'P':{'R':-1, 'S': 1, 'P':0}
- }
- return retval[p1][p2]
my_tuple = ((10, 10, 10, 12), (30, 45, 56, 45), (81, 80, 39, 32), (1, 2, 3, 4)) def average(tuples): return [sum(i) / len(i) for i in zip(*tuples)] print(f"\nAverage value: {average(my_tuple)}")
- my_tuple = ((10, 10, 10, 12), (30, 45, 56, 45), (81, 80, 39, 32), (1, 2, 3, 4))
- def average(tuples):
output_list = []for item in zip(*tuples):output_list.append(sum(item)/len(item))return output_list- return [sum(i) / len(i) for i in zip(*tuples)]
- print(f"\nAverage value: {average(my_tuple)}")
mylist = [("yellow", 1), ("blue", 2), ("yellow", 3), ("blue", 4), ("red", 1)] def group(lst, result={}): {result[c].append(n) if c in result else result.update({c: [n]}) for c, n in lst} return result print(group(mylist))
mylist = [('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)]- mylist = [("yellow", 1), ("blue", 2), ("yellow", 3), ("blue", 4), ("red", 1)]
def group(lst):dic = {}for i in lst:if i[0] not in dic:dic[i[0]] = [i[1]]else:dic[i[0]] = [*dic[i[0]], i[1]]return dic- def group(lst, result={}):
- {result[c].append(n) if c in result else result.update({c: [n]}) for c, n in lst}
- return result
- print(group(mylist))
package kata func SumLetters(a string, b string) bool { return len(a) == len(b) && len(a) > 0 }
def verify_sum(a, b)a&&b&&a.sum==b.sum||falseend- package kata
- func SumLetters(a string, b string) bool {
- return len(a) == len(b) && len(a) > 0
- }
package kata_test import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" . "codewarrior/kata" ) func dotest(a string, b string, expected bool) { actual := SumLetters(a, b) Expect(actual).To(Equal(expected)) } var _ = Describe("Tests", func() { It("Example 1", func() { dotest("Sebastian", "Patricia", false) }) It("Example 2", func() { dotest("Anna", "Nana", true) }) It("Example 3", func() { dotest("John", "", false) }) It("Example 4", func() { dotest("", "", false) }) })
# From Ruby 3.0, RSpec is used under the hood.# See https://rspec.info/# Defaults to the global `describe` for backwards compatibility, but `RSpec.desribe` works as well.describe "Example" doit "should return the sum" doexpect(verify_sum("Sebastian", "Patricia")).to eq(false)expect(verify_sum("Anna", "Nana")).to eq(true)expect(verify_sum("John", nil)).to eq(false)expect(verify_sum(nil, nil)).to eq(false)# The following is still supported, but new tests should now use them.# Test.assert_equals(add(1, 1), 2)endend- package kata_test
- import (
- . "github.com/onsi/ginkgo"
- . "github.com/onsi/gomega"
- . "codewarrior/kata"
- )
- func dotest(a string, b string, expected bool) {
- actual := SumLetters(a, b)
- Expect(actual).To(Equal(expected))
- }
- var _ = Describe("Tests", func() {
- It("Example 1", func() {
- dotest("Sebastian", "Patricia", false)
- })
- It("Example 2", func() {
- dotest("Anna", "Nana", true)
- })
- It("Example 3", func() {
- dotest("John", "", false)
- })
- It("Example 4", func() {
- dotest("", "", false)
- })
- })
I removed exactly three words from the code. Very helpful
const { createHash } = require("node:crypto"); const databaseUser = [ { email: "tvorchesky@mail.com", password: "6827ef24aa9c59195dc19cbc2b597f6d" /* password nya adalah Taralolet123, udah di enkripsi pakai MD5 */, }, ]; const md5 = (value) => createHash("md5").update(value).digest("hex"); function login(userEmail, userPassword) { return Boolean( databaseUser.find( ({ email, password }) => userEmail === email && password === md5(userPassword) ) ); }
const crypto = require("node:crypto");- const { createHash } = require("node:crypto");
- const databaseUser = [
- {
- email: "tvorchesky@mail.com",
- password:
- "6827ef24aa9c59195dc19cbc2b597f6d" /* password nya adalah Taralolet123, udah di enkripsi pakai MD5 */,
- },
- ];
const md5 = (value) => crypto.createHash("md5").update(value).digest("hex");- const md5 = (value) => createHash("md5").update(value).digest("hex");
- function login(userEmail, userPassword) {
const isExists = databaseUser.find(({ email, password }) =>userEmail === email && password === md5(userPassword),- return Boolean(
- databaseUser.find(
- ({ email, password }) =>
- userEmail === email && password === md5(userPassword)
- )
- );
return Boolean(isExists);- }
Made it a lambda and changed """ with "
text=lambda d="description",k="Kata or Kumite",r="return",s="symbols": f"Compress large text - {d} of this {k} in small code.\nThis {k} {d} has 462 {s} in 3 line, without title. You should wrote function, {r} this text, but you should use less {s} in you'r code that this text. Simple solution - just {r} \"\"\"source text\"\"\". More smart variant is: do mark often word as special {s} and replace his before {r}.\nHow small code can be? Can you wrote more compressing? Let's check it!"
def text():d,k,r,s="description","Kata or Kumite","return","symbols"return f"""Compress large text - {d} of this {k} in small code.This {k} {d} has 462 {s} in 3 line, without title. You should wrote function, {r} this text, but you should use less {s} in you'r code that this text. Simple solution - just {r} \"\"\"source text\"\"\". More smart variant is: do mark often word as special {s} and replace his before {r}.How small code can be? Can you wrote more compressing? Let's check it!"""- text=lambda d="description",k="Kata or Kumite",r="return",s="symbols": f"Compress large text - {d} of this {k} in small code.\nThis {k} {d} has 462 {s} in 3 line, without title. You should wrote function, {r} this text, but you should use less {s} in you'r code that this text. Simple solution - just {r} \"\"\"source text\"\"\". More smart variant is: do mark often word as special {s} and replace his before {r}.\nHow small code can be? Can you wrote more compressing? Let's check it!"
def kimite(grid): rows, cols = len(grid), len(grid[0]) # Burn method. Less optimal that Djikstra, but simple. hotmap=[[None for c in range(cols)] for r in range(rows)] hotmap[0][0]=grid[0][0] # first point changed=True itr=0 while changed: changed=False for r in range(rows): for c in range(cols): d=[] for y in [r-1,r+1,r]: for x in [c-1,c+1,c]: if (x>=0)and(y>=0) and (x<cols)and(y<rows) and ((x==c)or(y==r)) and (hotmap[y][x]!=None): d.append(hotmap[y][x]) if len(d)>0: k=grid[r][c]+min(d) if (hotmap[r][c]!=None) and (hotmap[r][c]<k): k=hotmap[r][c] if k!=hotmap[r][c]: changed=True hotmap[r][c]=k itr+=1 print('Iteration for search '+str(itr)) #print(hotmap) total_cost = hotmap[-1][-1] return total_cost
- def kimite(grid):
- rows, cols = len(grid), len(grid[0])
position = (0, 0)seen = set()total_cost = 0# Helper function to find the min cost based on current coordinatesdef get_step_cost(*directions, ):compare = sorted([i for i in directions if i != None], key=lambda x: x[0])multiple = [x for x in [i for i in directions if i != None] if x[0] == compare[0][0]]if len(multiple) > 1:for i in multiple:if i[1] == 'right':return ifor i in multiple:if i[1] == 'down':return ielse:return compare[0]# Helper function to find polar directionsdef get_direction():up, down, left, right = None, None, None, None# Check Yif position[0] > 0 and (position[0] - 1, position[1]) not in seen:up = (grid[position[0] - 1][position[1]], 'up')if position[0] + 1 < rows and (position[0] + 1, position[1]) not in seen:down = (grid[position[0] + 1][position[1]], 'down')# Check Xif position[1] > 0 and (position[0], position[1] - 1) not in seen:left = (grid[position[0]][position[1] - 1], 'left')if position[1] + 1 < cols and (position[0], position[1] + 1) not in seen:right = (grid[position[0]][position[1] + 1], 'right')return (up, down, left, right)# Traverse the grid to find the minimum cost pathwhile position != (rows - 1, cols - 1):direction = get_direction()cost, move = get_step_cost(*direction)if move == 'up':position = (position[0] - 1, position[1])total_cost += costseen.add(position)continueif move == 'down':position = (position[0] + 1, position[1])total_cost += costseen.add(position)continueif move == 'left':position = (position[0], position[1] - 1)total_cost += costseen.add(position)continueif move == 'right':position = (position[0], position[1] + 1)total_cost += costseen.add(position)- # Burn method. Less optimal that Djikstra, but simple.
- hotmap=[[None for c in range(cols)] for r in range(rows)]
- hotmap[0][0]=grid[0][0] # first point
- changed=True
- itr=0
- while changed:
- changed=False
- for r in range(rows):
- for c in range(cols):
- d=[]
- for y in [r-1,r+1,r]:
- for x in [c-1,c+1,c]:
- if (x>=0)and(y>=0) and (x<cols)and(y<rows) and ((x==c)or(y==r)) and (hotmap[y][x]!=None):
- d.append(hotmap[y][x])
- if len(d)>0:
- k=grid[r][c]+min(d)
- if (hotmap[r][c]!=None) and (hotmap[r][c]<k):
- k=hotmap[r][c]
- if k!=hotmap[r][c]:
- changed=True
- hotmap[r][c]=k
- itr+=1
- print('Iteration for search '+str(itr))
- #print(hotmap)
- total_cost = hotmap[-1][-1]
- return total_cost