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.

C++ : Iterating over two vectors at the same time till end of one
(with pair instead of tuple)

Code
Diff
  • #include <vector>
    #include <utility>
    #include <iostream>
    template <class T, class U>
    void iterateTwoVectors(std::vector<T> A, std::vector<U> B)
    {
    
       for (auto [a,b] = std::pair{A.begin(), B.begin()}; a != A.end() && b != B.end(); a++, b++) 
       { 
        std::cout << *a << ":" << *b << "\n";
       }
    }
  • 11
    #include <vector>
    
    2
    #include <tuple>
    
    2+
    #include <utility>
    
    33
    #include <iostream>
    
    44
    template <class T, class U>
    
    55
    void iterateTwoVectors(std::vector<T> A, std::vector<U> B)
    
    66
    {
    
    77
    8
       for (auto [a,b] = std::tuple{A.begin(), B.begin()}; a != A.end() && b != B.end(); a++, b++) 
    
    8+
       for (auto [a,b] = std::pair{A.begin(), B.begin()}; a != A.end() && b != B.end(); a++, b++) 
    
    99
       { 
    
    1010
        std::cout << *a << ":" << *b << "\n";
    
    1111
       }
    
    1212
    }
    

Recent Moves:

The sequel nobody asked for.

Code
Diff
  • bool Or(bool a,bool b){return 2>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))
    >>(1>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b)));}bool And(bool a,bool b){
    return 2>>(2>>a>>b>>(1>>a>>b))>>(2>>a>>b>>(1>>a>>b))>>(1>>(2>>a>>b>>(1>>a>>
    b))>>(2>>a>>b>>(1>>a>>b)));}bool Xor(bool a,bool b){return 2>>(2>>(2>>a>>b
    >>(1>>a>>b))>>(2>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))>>(1>>(2>>a>>a
    >>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))))>>(1>>(2>>a>>b>>(1>>a>>b))>>(2>>(2>>a>>
    a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))>>(1>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1
    >>b>>b))))))>>(2>>(2>>a>>b>>(1>>a>>b))>>(2>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b
    >>(1>>b>>b))>>(1>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))))>>(1>>(2>>a>>
    b>>(1>>a>>b))>>(2>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))>>(1>>(2>>a>>a
    >>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))))))>>(1>>(2>>(2>>a>>b>>(1>>a>>b))>>(2>>(
    2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))>>(1>>(2>>a>>a>>(1>>a>>a))>>(2>>b
    >>b>>(1>>b>>b))))>>(1>>(2>>a>>b>>(1>>a>>b))>>(2>>(2>>a>>a>>(1>>a>>a))>>(2>>
    b>>b>>(1>>b>>b))>>(1>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))))))>>(2>>(
    2>>a>>b>>(1>>a>>b))>>(2>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))>>(1>>(2
    >>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))))>>(1>>(2>>a>>b>>(1>>a>>b))>>(2>>(
    2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))>>(1>>(2>>a>>a>>(1>>a>>a))>>(2>>b
    >>b>>(1>>b>>b)))))));}
  • 1
    bool Or(bool a,bool b){return(~-((~-(a)*~-(b)))*~-((~-(a)*~-(b))));}bool And
    
    2
    (bool a,bool b){return(~-((~-(a)*~-(a)))*~-((~-(b)*~-(b))));}bool Xor(bool a
    
    3
    ,bool b){return(~-((~-((~-((~-((~-(a)*~-(a)))*~-((~-(b)*~-(b)))))*~-((~-(a)*
    
    4
    ~-(b)))))*~-((~-((~-((~-(a)*~-(a)))*~-((~-(b)*~-(b)))))*~-((~-(a)*~-(b))))))
    
    5
    )*~-((~-((~-((~-((~-(a)*~-(a)))*~-((~-(b)*~-(b)))))*~-((~-(a)*~-(b)))))*~-((
    
    6
    ~-((~-((~-(a)*~-(a)))*~-((~-(b)*~-(b)))))*~-((~-(a)*~-(b))))))));}
    
    1+
    bool Or(bool a,bool b){return 2>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))
    
    2+
    >>(1>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b)));}bool And(bool a,bool b){
    
    3+
    return 2>>(2>>a>>b>>(1>>a>>b))>>(2>>a>>b>>(1>>a>>b))>>(1>>(2>>a>>b>>(1>>a>>
    
    4+
    b))>>(2>>a>>b>>(1>>a>>b)));}bool Xor(bool a,bool b){return 2>>(2>>(2>>a>>b
    
    5+
    >>(1>>a>>b))>>(2>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))>>(1>>(2>>a>>a
    
    6+
    >>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))))>>(1>>(2>>a>>b>>(1>>a>>b))>>(2>>(2>>a>>
    
    7+
    a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))>>(1>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1
    
    8+
    >>b>>b))))))>>(2>>(2>>a>>b>>(1>>a>>b))>>(2>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b
    
    9+
    >>(1>>b>>b))>>(1>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))))>>(1>>(2>>a>>
    
    10+
    b>>(1>>a>>b))>>(2>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))>>(1>>(2>>a>>a
    
    11+
    >>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))))))>>(1>>(2>>(2>>a>>b>>(1>>a>>b))>>(2>>(
    
    12+
    2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))>>(1>>(2>>a>>a>>(1>>a>>a))>>(2>>b
    
    13+
    >>b>>(1>>b>>b))))>>(1>>(2>>a>>b>>(1>>a>>b))>>(2>>(2>>a>>a>>(1>>a>>a))>>(2>>
    
    14+
    b>>b>>(1>>b>>b))>>(1>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))))))>>(2>>(
    
    15+
    2>>a>>b>>(1>>a>>b))>>(2>>(2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))>>(1>>(2
    
    16+
    >>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))))>>(1>>(2>>a>>b>>(1>>a>>b))>>(2>>(
    
    17+
    2>>a>>a>>(1>>a>>a))>>(2>>b>>b>>(1>>b>>b))>>(1>>(2>>a>>a>>(1>>a>>a))>>(2>>b
    
    18+
    >>b>>(1>>b>>b)))))));}
    
Fundamentals
Loops
Control Flow
Basic Language Features
Code
Diff
  • import sqlite3
    
    def sort_arr(arr):
        cursor = sqlite3.connect(":memory:").cursor()
        cursor.execute("CREATE TABLE data (value INTEGER);")
        cursor.executemany(
            "INSERT INTO data VALUES (?)", 
            map(lambda x: (x,), arr)
        )
        cursor.execute( "SELECT value FROM data ORDER BY value;")
        solution = cursor.fetchall()
        cursor.execute("DROP TABLE data;")
        return [*map(lambda xs: xs[0], solution)]
    
  • 1
    import queue
    
    1+
    import sqlite3
    
    22
    33
    def sort_arr(arr):
    
    4
        pq = queue.PriorityQueue(maxsize=len(arr))
    
    5
        for x in arr:
    
    6
            pq.put(x)
    
    7
        return [pq.get() for _0 in range(len(arr))]
    
    4+
        cursor = sqlite3.connect(":memory:").cursor()
    
    5+
        cursor.execute("CREATE TABLE data (value INTEGER);")
    
    6+
        cursor.executemany(
    
    7+
            "INSERT INTO data VALUES (?)", 
    
    8+
            map(lambda x: (x,), arr)
    
    9+
        )
    
    10+
        cursor.execute( "SELECT value FROM data ORDER BY value;")
    
    11+
        solution = cursor.fetchall()
    
    12+
        cursor.execute("DROP TABLE data;")
    
    13+
        return [*map(lambda xs: xs[0], solution)]
    

Recent Moves:

Control Flow
Basic Language Features
Fundamentals

Pretty elegant.

Code
Diff
  • module Nigelius where
    
    getBonusDamage :: Integer -> Integer
    getBonusDamage = flip (^) 2 . flip div 250
  • 1
    function getBonusDamage(currentHP) {
    
    2
      return Math.trunc(currentHP / 250) ** 2
    
    3
    }
    
    1+
    module Nigelius where
    
    2+
    3+
    getBonusDamage :: Integer -> Integer
    
    4+
    getBonusDamage = flip (^) 2 . flip div 250
    

Recent Moves:

Arithmetic
Mathematics
Algorithms
Numbers
Code
Diff
  • from math import gcd
    
    def greatest_common_divisor(*args):
        # iterates through entirety of args every time
        return __import__("functools").reduce(gcd, args)
    
    def greatest_common_divisor(*args):
        acc = args[0]
        for i in range(1, len(args)):
            if acc == 1:
                return 1
            acc = gcd(acc, args[i])
        return acc
    
  • 1
    def greatest_common_divisor(*args):
    
    1+
    from math import gcd
    
    22
    3
        def gcd(a, b):
    
    4
            if a == b: return a
    
    5
            elif a > b:
    
    6
                return (gcd(b, a % b) if a % b != 0 else b)
    
    7
            else:
    
    8
                return gcd(b, a)
    
    3+
    def greatest_common_divisor(*args):
    
    4+
        # iterates through entirety of args every time
    
    5+
        return __import__("functools").reduce(gcd, args)
    
    99
    10
        res = gcd(args[0], args[1])
    
    11
        if len(args) > 2:
    
    12
            for i in range(2, len(args)):
    
    13
                res = gcd(res, args[i])
    
    14
        return res
    
    7+
    def greatest_common_divisor(*args):
    
    8+
        acc = args[0]
    
    9+
        for i in range(1, len(args)):
    
    10+
            if acc == 1:
    
    11+
                return 1
    
    12+
            acc = gcd(acc, args[i])
    
    13+
        return acc