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
  • 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))
Code
Diff
  • 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||false
    • end
    • package kata
    • func SumLetters(a string, b string) bool {
    • return len(a) == len(b) && len(a) > 0
    • }

I removed exactly three words from the code. Very helpful

Code
Diff
  • 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);
    • }
Sets
Code
Diff
  • 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 "

Code
Diff
  • 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!"
Code
Diff
  • 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 coordinates
    • def 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 i
    • for i in multiple:
    • if i[1] == 'down':
    • return i
    • else:
    • return compare[0]
    • # Helper function to find polar directions
    • def get_direction():
    • up, down, left, right = None, None, None, None
    • # Check Y
    • if 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 X
    • if 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 path
    • while 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 += cost
    • seen.add(position)
    • continue
    • if move == 'down':
    • position = (position[0] + 1, position[1])
    • total_cost += cost
    • seen.add(position)
    • continue
    • if move == 'left':
    • position = (position[0], position[1] - 1)
    • total_cost += cost
    • seen.add(position)
    • continue
    • if move == 'right':
    • position = (position[0], position[1] + 1)
    • total_cost += cost
    • seen.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
Code
Diff
  • #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);
    • }
Matrix
Code
Diff
  • 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]] = writedata
    • return matrix
    • else:
    • 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