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

Return None if the given input array is not missing a natural sequence.

Code
Diff
  • class MissingInteger:
        def __init__(self, arr):
            self.arr = arr
            self.temp = [i for i in range(min(self.arr), max(self.arr) + 1)]
    
        def solution(self):
            for x, y in zip(self.arr, self.temp):
                if x != y:
                    return y      
            return None
    
    • class MissingInteger:
    • def __init__(self, arr):
    • self.arr = arr
    • self.temp = [i for i in range(min(self.arr), max(self.arr) + 1)]
    • def solution(self):
    • xor = 1
    • for i, el in enumerate(self.arr):
    • if self.arr[i] != 0:
    • xor ^= self.arr[i]
    • xor ^= len(self.arr) + 1
    • return xor
    • for x, y in zip(self.arr, self.temp):
    • if x != y:
    • return y
    • return None
Code
Diff
  • #include<bits/stdc++.h>
    using namespace std;
    
    long add_arr(vector<int> arr)
    {
      return std::reduce(begin(arr),end(arr));
    }
    • #include<bits/stdc++.h>
    • using namespace std;
    • long add_arr(vector<int> arr)
    • {
    • return std::accumulate(begin(arr),end(arr),0);
    • return std::reduce(begin(arr),end(arr));
    • }
Fundamentals

Represents an ordinal numeral (i.e. 1st, 24th, etc.)

Code
Diff
  • from __future__ import annotations
    
    
    class OrdinalNumeral:
        def __init__(self, n: int):
            """Represents an ordinal numeral (i.e. 1st, 24th, etc.)
    
            :param int n: The integer to represent
            :raises ValueError: Raised if n is below 0
            :raises TypeError: Raised if a non-integer/OrdinalNumber value is added to the number
            """
            if n < 0:
                raise ValueError("n must be positive or 0")
            self._n = n
    
        @property
        def n(self):
            return self._n
    
        @n.setter
        def n(self, n: int):
            if n < 0:
                raise ValueError("n must be positive or 0")
            self._n = n
    
        @property
        def numeral(self):
            if 11 <= (self.n % 100) <= 13:
                return str(self.n) + "th"
            return str(self.n) + ("th", "st", "nd", "rd", "th")[min(4, self.n % 10)]
    
        def __repr__(self):
            """Representation that can be used to recreate the object"""
            return f"OrdinalNumeral(n={self.n})"
    
        def __str__(self):
            """The 'nice' string version of the class"""
            return self.numeral
    
        def __int__(self):
            return self.n
    
        def __add__(self, other: int | OrdinalNumeral):
            """Can implement arithmetic operations if desired"""
            if isinstance(other, OrdinalNumeral):
                return OrdinalNumeral(self.n + other.n)
            elif isinstance(other, int):
                return OrdinalNumeral(self.n + other)
            else:
                raise TypeError(f"Unable to add {type(other)} with OrdinalNumeral")
    
    • from __future__ import annotations
    • class OrdinalNumeral:
    • def __init__(self, n: int):
    • if n < 0: raise ValueError("n must be positive or 0")
    • self.n = n
    • self.numeral = self._numeral()
    • """Represents an ordinal numeral (i.e. 1st, 24th, etc.)
    • :param int n: The integer to represent
    • :raises ValueError: Raised if n is below 0
    • :raises TypeError: Raised if a non-integer/OrdinalNumber value is added to the number
    • """
    • if n < 0:
    • raise ValueError("n must be positive or 0")
    • self._n = n
    • @property
    • def n(self):
    • return self._n
    • @n.setter
    • def n(self, n: int):
    • if n < 0:
    • raise ValueError("n must be positive or 0")
    • self._n = n
    • @property
    • def numeral(self):
    • if 11 <= (self.n % 100) <= 13:
    • return str(self.n) + "th"
    • return str(self.n) + ("th", "st", "nd", "rd", "th")[min(4, self.n % 10)]
    • def __repr__(self):
    • """representation that can be used to recreate the object"""
    • return f"OrdinalNumeral(self.n)"
    • """Representation that can be used to recreate the object"""
    • return f"OrdinalNumeral(n={self.n})"
    • def __str__(self):
    • """the 'nice' string version of the class"""
    • """The 'nice' string version of the class"""
    • return self.numeral
    • def __int__(self):
    • return self.n
    • def __add__(self, other):
    • """can implement arithmetic operations if desired"""
    • if (isinstance(other, OrdinalNumeral)): return OrdinalNumeral(self.n + other.n)
    • elif (isinstance(other, int)): return OrdinalNumeral(self.n + other)
    • else: raise TypeError(f"Unable to add {type(other)} with OrdinalNumeral")
    • def _numeral(self):
    • """define the ordinal numeral string"""
    • if 11 <= (self.n % 100) <= 13: return str(self.n)+"th"
    • return str(self.n)+("th", "st", "nd", "rd", "th")[min(4, self.n % 10)]
    • def __add__(self, other: int | OrdinalNumeral):
    • """Can implement arithmetic operations if desired"""
    • if isinstance(other, OrdinalNumeral):
    • return OrdinalNumeral(self.n + other.n)
    • elif isinstance(other, int):
    • return OrdinalNumeral(self.n + other)
    • else:
    • raise TypeError(f"Unable to add {type(other)} with OrdinalNumeral")
Code
Diff
  • module Solution (fizzbuzz) where
    
    make_mod_repr d repr n | n `mod` d == 0 = Just repr
                           | otherwise      = Nothing
                           
    mod_3_repr = make_mod_repr 3 "fizz"
    mod_5_repr = make_mod_repr 5 "buzz"
    
    fizzbuzz :: [String] -> Int -> Int -> [String]
    fizzbuzz _ i n = map fizzbuzz' [i .. n]
      where
        fizzbuzz' x | repr == Nothing = show x
                    | otherwise       = (\(Just x) -> x) repr
            where 
                repr = foldl (\acc f -> acc <> f x) Nothing [mod_3_repr, mod_5_repr]
    
    -- we don't need the empty accumulator
    -- could be fizzbuzz :: Int -> Int -> [String]
    • module Solution where
    • module Solution (fizzbuzz) where
    • make_mod_repr d repr n | n `mod` d == 0 = Just repr
    • | otherwise = Nothing
    • mod_3_repr = make_mod_repr 3 "fizz"
    • mod_5_repr = make_mod_repr 5 "buzz"
    • fizzbuzz :: [String] -> Int -> Int -> [String]
    • fizzbuzz _ i n = map fizzbuzz' [i .. n]
    • where
    • fizzbuzz' x | repr == Nothing = show x
    • | otherwise = (\(Just x) -> x) repr
    • where
    • repr = foldl (\acc f -> acc <> f x) Nothing [mod_3_repr, mod_5_repr]
    • -- we don't need the empty accumulator
    • -- could be fizzbuzz :: Int -> Int -> [String]
Code
Diff
  • SELECT * 
    FROM employees emp
    WHERE emp.salary>5000000 AND emp.months>=12
    ORDER BY emp.salary DESC
    • select * from employees where employees.salary>5000000 and employees.months>=12
    • order by employees.salary desc
    • SELECT *
    • FROM employees emp
    • WHERE emp.salary>5000000 AND emp.months>=12
    • ORDER BY emp.salary DESC
Code
Diff
  • function* blaze_it() {
      yield 69;
      yield 420;
      yield 1337;
    }
    
    const dark_tech = blaze_it();
    
    let a = 10;
    a = dark_tech.next().value; // a = 69
    a = dark_tech.next().value; // a = 420
    a = dark_tech.next().value; // a = 1337
    const b = 42;
    a = 10 * b; // a = 420
    a = 17; // a = 17
    a -= Math.sin(Math.PI / 2); // a = 16
    a = a ^ 69; // a = 85
    a = 420; // a = 420
    
    console.log(a); // Output: 420
    
    • function* blaze_it() {
    • yield 69;
    • yield 420;
    • yield 1337;
    • };
    • }
    • const dark_tech = blaze_it()
    • const dark_tech = blaze_it();
    • let a=10;
    • a = dark_tech.next().value;
    • a = dark_tech.next().value;
    • a = dark_tech.next().value;
    • let a = 10;
    • a = dark_tech.next().value; // a = 69
    • a = dark_tech.next().value; // a = 420
    • a = dark_tech.next().value; // a = 1337
    • const b = 42;
    • a = 10*b;
    • a= 17;
    • a - Math.sin(Math.PI / 2);
    • a = a^69;
    • a=420;
    • a = 10 * b; // a = 420
    • a = 17; // a = 17
    • a -= Math.sin(Math.PI / 2); // a = 16
    • a = a ^ 69; // a = 85
    • a = 420; // a = 420
    • console.log(a); // Output: 420