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

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
Code
Diff
  • const crypto = 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");
    
    function login(userEmail, userPassword) {
      const isExists = databaseUser.find(
        ({ email, password }) =>
          userEmail === email && password === md5(userPassword),
      );
      return Boolean(isExists);
    }
    
    • var databaseUser = [
    • {
    • email : "tvorchesky@mail.com",
    • password : "6827ef24aa9c59195dc19cbc2b597f6d" /* password nya adalah Taralolet123, udah di enkripsi pakai MD5 */
    • }
    • const crypto = require("node:crypto");
    • const databaseUser = [
    • {
    • email: "tvorchesky@mail.com",
    • password:
    • "6827ef24aa9c59195dc19cbc2b597f6d" /* password nya adalah Taralolet123, udah di enkripsi pakai MD5 */,
    • },
    • ];
    • const MD5 = d => {var r = M(V(Y(X(d),8*d.length)));return r.toLowerCase()};function M(d){for(var _,m="0123456789ABCDEF",f="",r=0;r<d.length;r++)_=d.charCodeAt(r),f+=m.charAt(_>>>4&15)+m.charAt(15&_);return f}function X(d){for(var _=Array(d.length>>2),m=0;m<_.length;m++)_[m]=0;for(m=0;m<8*d.length;m+=8)_[m>>5]|=(255&d.charCodeAt(m/8))<<m%32;return _}function V(d){for(var _="",m=0;m<32*d.length;m+=8)_+=String.fromCharCode(d[m>>5]>>>m%32&255);return _}function Y(d,_){d[_>>5]|=128<<_%32,d[14+(_+64>>>9<<4)]=_;for(var m=1732584193,f=-271733879,r=-1732584194,i=271733878,n=0;n<d.length;n+=16){var h=m,t=f,g=r,e=i;f=md5_ii(f=md5_ii(f=md5_ii(f=md5_ii(f=md5_hh(f=md5_hh(f=md5_hh(f=md5_hh(f=md5_gg(f=md5_gg(f=md5_gg(f=md5_gg(f=md5_ff(f=md5_ff(f=md5_ff(f=md5_ff(f,r=md5_ff(r,i=md5_ff(i,m=md5_ff(m,f,r,i,d[n+0],7,-680876936),f,r,d[n+1],12,-389564586),m,f,d[n+2],17,606105819),i,m,d[n+3],22,-1044525330),r=md5_ff(r,i=md5_ff(i,m=md5_ff(m,f,r,i,d[n+4],7,-176418897),f,r,d[n+5],12,1200080426),m,f,d[n+6],17,-1473231341),i,m,d[n+7],22,-45705983),r=md5_ff(r,i=md5_ff(i,m=md5_ff(m,f,r,i,d[n+8],7,1770035416),f,r,d[n+9],12,-1958414417),m,f,d[n+10],17,-42063),i,m,d[n+11],22,-1990404162),r=md5_ff(r,i=md5_ff(i,m=md5_ff(m,f,r,i,d[n+12],7,1804603682),f,r,d[n+13],12,-40341101),m,f,d[n+14],17,-1502002290),i,m,d[n+15],22,1236535329),r=md5_gg(r,i=md5_gg(i,m=md5_gg(m,f,r,i,d[n+1],5,-165796510),f,r,d[n+6],9,-1069501632),m,f,d[n+11],14,643717713),i,m,d[n+0],20,-373897302),r=md5_gg(r,i=md5_gg(i,m=md5_gg(m,f,r,i,d[n+5],5,-701558691),f,r,d[n+10],9,38016083),m,f,d[n+15],14,-660478335),i,m,d[n+4],20,-405537848),r=md5_gg(r,i=md5_gg(i,m=md5_gg(m,f,r,i,d[n+9],5,568446438),f,r,d[n+14],9,-1019803690),m,f,d[n+3],14,-187363961),i,m,d[n+8],20,1163531501),r=md5_gg(r,i=md5_gg(i,m=md5_gg(m,f,r,i,d[n+13],5,-1444681467),f,r,d[n+2],9,-51403784),m,f,d[n+7],14,1735328473),i,m,d[n+12],20,-1926607734),r=md5_hh(r,i=md5_hh(i,m=md5_hh(m,f,r,i,d[n+5],4,-378558),f,r,d[n+8],11,-2022574463),m,f,d[n+11],16,1839030562),i,m,d[n+14],23,-35309556),r=md5_hh(r,i=md5_hh(i,m=md5_hh(m,f,r,i,d[n+1],4,-1530992060),f,r,d[n+4],11,1272893353),m,f,d[n+7],16,-155497632),i,m,d[n+10],23,-1094730640),r=md5_hh(r,i=md5_hh(i,m=md5_hh(m,f,r,i,d[n+13],4,681279174),f,r,d[n+0],11,-358537222),m,f,d[n+3],16,-722521979),i,m,d[n+6],23,76029189),r=md5_hh(r,i=md5_hh(i,m=md5_hh(m,f,r,i,d[n+9],4,-640364487),f,r,d[n+12],11,-421815835),m,f,d[n+15],16,530742520),i,m,d[n+2],23,-995338651),r=md5_ii(r,i=md5_ii(i,m=md5_ii(m,f,r,i,d[n+0],6,-198630844),f,r,d[n+7],10,1126891415),m,f,d[n+14],15,-1416354905),i,m,d[n+5],21,-57434055),r=md5_ii(r,i=md5_ii(i,m=md5_ii(m,f,r,i,d[n+12],6,1700485571),f,r,d[n+3],10,-1894986606),m,f,d[n+10],15,-1051523),i,m,d[n+1],21,-2054922799),r=md5_ii(r,i=md5_ii(i,m=md5_ii(m,f,r,i,d[n+8],6,1873313359),f,r,d[n+15],10,-30611744),m,f,d[n+6],15,-1560198380),i,m,d[n+13],21,1309151649),r=md5_ii(r,i=md5_ii(i,m=md5_ii(m,f,r,i,d[n+4],6,-145523070),f,r,d[n+11],10,-1120210379),m,f,d[n+2],15,718787259),i,m,d[n+9],21,-343485551),m=safe_add(m,h),f=safe_add(f,t),r=safe_add(r,g),i=safe_add(i,e)}return Array(m,f,r,i)}function md5_cmn(d,_,m,f,r,i){return safe_add(bit_rol(safe_add(safe_add(_,d),safe_add(f,i)),r),m)}function md5_ff(d,_,m,f,r,i,n){return md5_cmn(_&m|~_&f,d,_,r,i,n)}function md5_gg(d,_,m,f,r,i,n){return md5_cmn(_&f|m&~f,d,_,r,i,n)}function md5_hh(d,_,m,f,r,i,n){return md5_cmn(_^m^f,d,_,r,i,n)}function md5_ii(d,_,m,f,r,i,n){return md5_cmn(m^(_|~f),d,_,r,i,n)}function safe_add(d,_){var m=(65535&d)+(65535&_);return(d>>16)+(_>>16)+(m>>16)<<16|65535&m}function bit_rol(d,_){return d<<_|d>>>32-_}
    • function login(email, password){
    • const isExists = databaseUser.filter(d => (d.email === email && d.password === MD5(password)));
    • return isExists.length > 0
    • }
    • const md5 = (value) => crypto.createHash("md5").update(value).digest("hex");
    • function login(userEmail, userPassword) {
    • const isExists = databaseUser.find(
    • ({ email, password }) =>
    • userEmail === email && password === md5(userPassword),
    • );
    • return Boolean(isExists);
    • }
  • 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
Code
Diff
  • const tab = (func, start, end, step) => {
      let sum = 0;
      const count = Math.ceil((end - start) / step) + 1;
      for (let i = 0; i < count; i++) {
        sum += func(start + i * step);
      }
      return sum;
    }
    • const tab = (f, a, b, h) => {
    • return Array.from(
    • {
    • length: Math.ceil((b - a) / h) + 1
    • },
    • (v, i) => f(a + (i * h))).reduce((a, c) => a += c, 0
    • )
    • }
    • const tab = (func, start, end, step) => {
    • let sum = 0;
    • const count = Math.ceil((end - start) / step) + 1;
    • for (let i = 0; i < count; i++) {
    • sum += func(start + i * step);
    • }
    • return sum;
    • }
Code
Diff
  • #include <stdbool.h>
    
    bool odd_even(int n)
    {
        return n < 0 || n > 1 ? odd_even(n + 2 * (n < 0 ? 1 : -1)) : !n;
    }
    • #include <stdbool.h>
    • bool odd_even(int n)
    • {
    • int r = 0, p[1] = {0};
    • goto owo;
    • uwu:
    • *&*p = (&r)[0];
    • goto miau;
    • owo:
    • *(int*)((void*)&r) = n%2;
    • goto uwu;
    • miau:
    • return !(*p&1) ? true : false;
    • return n < 0 || n > 1 ? odd_even(n + 2 * (n < 0 ? 1 : -1)) : !n;
    • }