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.
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);- }
def dumbRockPaperScissors(p1,p2,rpc={"Rock":"Paper","Paper":"Scissors","Scissors":"Rock"}): if p1 in rpc[p2]: return "Player 1 wins" if p2 in rpc[p1]: return "Player 2 wins" return "Draw"
def dumbRockPaperScissors(player1, player2):Rock = {"Paper"}Paper = {"Scissors"}Scissors = {"Rock"}if player1 in eval(player2):return "Player 1 wins"if player2 in eval(player1):return "Player 2 wins"- def dumbRockPaperScissors(p1,p2,rpc={"Rock":"Paper","Paper":"Scissors","Scissors":"Rock"}):
- if p1 in rpc[p2]: return "Player 1 wins"
- if p2 in rpc[p1]: return "Player 2 wins"
- return "Draw"
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
- No need for redundant size == 1 check!
- Also added template
#include <vector> #include <numeric> template <typename T = double> int sum(const std::vector<T>& v) { return v.size() == 0 ? -1 : std::accumulate(v.begin(), v.end(), 0); }
- #include <vector>
- #include <numeric>
int sum(std::vector<int>& v) {- template <typename T = double>
- int sum(const std::vector<T>& v) {
- return v.size() == 0 ? -1
: v.size() == 1 ? v[0]- : std::accumulate(v.begin(), v.end(), 0);
- }
class OperationError(Exception): def __init__(self, message): super().__init__(message) def matrix(matrix=list, operation=str, location=tuple, writedata=None): def op_write(i,j): matrix[i][j] = writedata return matrix op={"read":lambda i,j: matrix[i][j], "write":op_write} try: if not operation in op: raise OperationError("That is not a valid operation for this system.") return op[operation](location[0],location[1]) except Exception as e: print(e) return -1
- class OperationError(Exception):
- def __init__(self, message):
- super().__init__(message)
- def matrix(matrix=list, operation=str, location=tuple, writedata=None):
- def op_write(i,j):
- matrix[i][j] = writedata
- return matrix
- op={"read":lambda i,j: matrix[i][j], "write":op_write}
- try:
if operation == "read":return matrix[location[0]][location[1]]elif operation == "write":matrix[location[0]][location[1]] = writedatareturn matrixelse:raise OperationError("That is not a valid operation for this system.")- if not operation in op: raise OperationError("That is not a valid operation for this system.")
- return op[operation](location[0],location[1])
- except Exception as e:
- print(e)
return -1- return -1