Begin a new Kumite
Search
About
  • Filter by Language:
  • 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.

Code
Diff
  • from random import randint
    
    def rubegoldberg():
        return randint(1, 10**randint(1, 10)) ** 0
  • 1
    import random
    
    1+
    from random import randint
    
    22
    33
    def rubegoldberg():
    
    4
        find = "codewars"
    
    5
        total = 1 - len(find)
    
    6
    7
        for x, y in enumerate(find):
    
    8
            if x % 2:
    
    9
                total -= ord(y) - 97
    
    10
            else:
    
    11
                total += ord(y) - 97        
    
    12
    13
        for n in random.sample([i for i in range(10)], 10):
    
    14
            if n:
    
    15
                a = 1 / n
    
    16
            else:
    
    17
                return total
    
    4+
        return randint(1, 10**randint(1, 10)) ** 0
    
Code
Diff
  • def pri(n):
        return n == 2 or n % 2 and n > 2 and all(n % i for i in range(3, int(n ** .5) + 1, 2))
    
    def Number_of_Primes(n):
        if not isinstance(n, int) or n < 0:
            return "Invalid input"
        prime = [2]
        i = 3
        while len(prime) < n:
            if pri(i):
                prime.append(i)
            i += 2
        return prime
    
  • 1
    def pri(n,p):#a simple function to loop over your primes 
    
    2
        for i in p:
    
    3
            if(n%i==0):return False
    
    4
        return True 
    
    1+
    def pri(n):
    
    2+
        return n == 2 or n % 2 and n > 2 and all(n % i for i in range(3, int(n ** .5) + 1, 2))
    
    3+
    55
    def Number_of_Primes(n):
    
    6
        prm,x=[2,3],5 #start with your intial prime numbers
    
    7
        while(len(prm)<n): #loop over all odd numbers until your reach your wanted number of primes
    
    8
            #check if this number is divisible by any of the former prime numbers
    
    9
            if(pri(x,prm)):prm.append(x)
    
    10
            x=x+2
    
    11
        return prm
    
    5+
        if not isinstance(n, int) or n < 0:
    
    6+
            return "Invalid input"
    
    7+
        prime = [2]
    
    8+
        i = 3
    
    9+
        while len(prime) < n:
    
    10+
            if pri(i):
    
    11+
                prime.append(i)
    
    12+
            i += 2
    
    13+
        return prime
    
Code
Diff
  • def final_price(price):
        return round(price*(1.1+(0.3 if price>=1e3 else 0)), 2)
  • 11
    def final_price(price):
    
    2
        vat = 0.1
    
    3
        lux = 0.3
    
    4
        
    
    5
        return round(price*(1+vat+lux),2) if price >= 1000 else round(price*(1+vat),2) 
    
    2+
        return round(price*(1.1+(0.3 if price>=1e3 else 0)), 2)
    
Code
Diff
  • digital_root=lambda n:digital_root(sum(map(int, str(n))))if n>9 else n
  • 1
    digital_root=lambda n:digital_root(sum(int(i) for i in str(n)))if n>9 else n
    
    1+
    digital_root=lambda n:digital_root(sum(map(int, str(n))))if n>9 else n
    
Code
Diff
  • // fixed
    int foo() { return 1; }
    int bar() { return 2; }
    int baz() { return 3; }
  • 1+
    // fixed
    
    11
    int foo() { return 1; }
    
    22
    int bar() { return 2; }
    
    33
    int baz() { return 3; }
    
SouljaBoiFailed Tests

test

AWDawdawdawdawd

public class wdawd() {
  int dadaf = 1;
  
  
}

Lambda with ternary operator

Code
Diff
  • power_of_two = lambda n: (False, True)[n % 2 == 0]
  • 1
    power_of_two = lambda n: n % 2 == 0;
    
    1+
    power_of_two = lambda n: (False, True)[n % 2 == 0]
    
Code
Diff
  • add(a,[b=0])=>'candy';var pekora=add;
  • 1
    pekora(a,b)=> 'candy';
    
    2
    add(a)=> 'candy';
    
    1+
    add(a,[b=0])=>'candy';var pekora=add;
    

Recent Moves:

Code
Diff
  • #include <vector>
    #include <string>
    #include <iostream>
    
    bool possible(unsigned i, char n, std::string& grid) //check if is possible placing element 'n' in 'i' position of the string
    {
      //the controls must be done relative to columns and rows, so it's necessary converting 'i' to the relative col and row
      unsigned c = i % 9;
      unsigned r = i / 9;
      unsigned c0 = (c / 3) * 3, r0 = (r / 3) * 3;
      
      for(unsigned k = 0; k < 9; k++)
        if(grid[9 * r + k] == n || grid[9 * k + c] == n || grid[9 * (r0 + k / 3) + (c0 + k % 3)] == n) 
          return false;
      return true;
    }
    
    bool backtrack(std::string& grid) //recursively try to fill the scheme with possible solutions, till it fills the whole scheme
    {
      for(unsigned i = 0; i < 81; i++)
        if(grid[i] == '0')
        {
          for(char n = '1'; n <= '9'; n++)
          if(possible(i, n, grid))
            {
              grid[i] = n;
              if(backtrack(grid)) return true;
              grid[i] = '0';
            }
          return false;
        }
      return true;
    }
    
    std::string solve_sudoku(std::string puzzleString)
    {
      backtrack(puzzleString);
      return puzzleString;
    }
  • 11
    #include <vector>
    
    22
    #include <string>
    
    3+
    #include <iostream>
    
    33
    4
    /* Sudokus are good examples for backtracking 
    
    5
    *  The algorithm try to place numbers in the empty spots untill it can or untill it solves the puzzle
    
    6
    */
    
    7
    8
    /* The first function determine if, in the grid "grid" at position x and y an n is acceptable. 
    
    9
    *  The k is used to iterate each subset: row, column and square, where x0 and y0 are the coordinates of the top left corner of the square
    
    10
    */
    
    11
    bool possible(unsigned x, unsigned y, int n, std::vector<std::vector<int>>& grid)
    
    5+
    bool possible(unsigned i, char n, std::string& grid) //check if is possible placing element 'n' in 'i' position of the string
    
    1212
    {
    
    13
      unsigned x0 = (x / 3) * 3, y0 = (y / 3) * 3;
    
    7+
      //the controls must be done relative to columns and rows, so it's necessary converting 'i' to the relative col and row
    
    8+
      unsigned c = i % 9;
    
    9+
      unsigned r = i / 9;
    
    10+
      unsigned c0 = (c / 3) * 3, r0 = (r / 3) * 3;
    
    11+
      
    
    1414
      for(unsigned k = 0; k < 9; k++)
    
    15
        if(grid[y][k] == n || grid[k][x] == n || grid[y0 + k / 3][x0 + k % 3] == n) 
    
    13+
        if(grid[9 * r + k] == n || grid[9 * k + c] == n || grid[9 * (r0 + k / 3) + (c0 + k % 3)] == n) 
    
    1616
          return false;
    
    1717
      return true;
    
    1818
    }
    
    1919
    20
    /* The backtracking function is a recursive function! each call keeps track of it's own x and y coordinates.
    
    21
    *  The function operates on a referenced grid. It scans each xy couple and, if it's zero, it tryes to put a number, checked with the "possible" funciton.
    
    22
    *  If the number is ok, then the function call itself.
    
    23
    *  Now, if the recursion find a solution then returns true so all the parent calls know the solution has been found. Otherwise, the parent function try to
    
    24
    *  go ahead and try another possible number.
    
    25
    */
    
    26
    bool backtrack(std::vector<std::vector<int>>& grid)
    
    18+
    bool backtrack(std::string& grid) //recursively try to fill the scheme with possible solutions, till it fills the whole scheme
    
    2727
    {
    
    28
      for(unsigned y = 0; y < 9; y++)
    
    29
        for(unsigned x = 0; x < 9; x++)
    
    30
          if(grid[y][x] == 0)
    
    31
          {
    
    32
            for(unsigned n = 1; n <= 9; n++)
    
    33
              if(possible(x, y, n, grid))
    
    39
            return false;
    
    40
          }
    
    20+
      for(unsigned i = 0; i < 81; i++)
    
    21+
        if(grid[i] == '0')
    
    22+
        {
    
    23+
          for(char n = '1'; n <= '9'; n++)
    
    24+
          if(possible(i, n, grid))
    
    25+
            {
    
    26+
              grid[i] = n;
    
    27+
              if(backtrack(grid)) return true;
    
    28+
              grid[i] = '0';
    
    29+
            }
    
    30+
          return false;
    
    31+
        }
    
    4141
      return true;
    
    4242
    }
    
    4343
    44
    /* The main function parses the string (Why the string tho?) and then parses the solution.
    
    45
    *  In this case, it won't check if a puzzle is impossible to solbe
    
    46
    */
    
    4747
    std::string solve_sudoku(std::string puzzleString)
    
    4848
    {
    
    49
      std::vector<std::vector<int>> puzzle(9, std::vector<int>(9, 0));
    
    50
      
    
    51
      for(unsigned i = 0; i < 81; i++)
    
    52
        puzzle[i / 9][i % 9] = puzzleString[i] - '0';
    
    53
      
    
    54
      backtrack(puzzle);
    
    55
      
    
    56
      std::string out = "";
    
    57
      for(auto& i : puzzle)
    
    58
        for(auto& j : i)
    
    59
          out += std::to_string(j);
    
    60
      return out;
    
    37+
      backtrack(puzzleString);
    
    38+
      return puzzleString;
    
    6161
    }