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.

Mathematics
Algorithms
Numbers
Code
Diff
  • """
    https://en.wikipedia.org/wiki/Primality_test
    An alternative using primality mod 30 = 2 * 3 * 5 instead of 6 = 2 * 3
    -- Using generator instead of list (works faster)
    """
    def prime_checker(n):
        if n in [2, 3, 5]:
            return True
        elif n % 2 == 0 or n % 3 == 0 or n % 5 == 0 or n <= 1:
            return False
        
        sqrt_n = int(n ** 0.5 / 30)
        b = [7, 11, 13, 17, 19, 23, 29, 31]
        
        for i in (30 * k for k in range(sqrt_n + 1)):
            if any(n % (i + j) == 0 for j in b if i + j is not n):
                return False
        return True
  • 11
    """
    
    22
    https://en.wikipedia.org/wiki/Primality_test
    
    3
    This one has lesser tests or usage of % operator.
    
    4
    An alternative using primality mod 30 = 2 * 3 * 5 instead of 6 = 2 * 3 
    
    3+
    An alternative using primality mod 30 = 2 * 3 * 5 instead of 6 = 2 * 3
    
    4+
    -- Using generator instead of list (works faster)
    
    55
    """
    
    66
    def prime_checker(n):
    
    77
        if n in [2, 3, 5]:
    
    88
            return True
    
    9
        elif n % 2 == 0 or n % 3 == 0 or n % 5 == 0:
    
    9+
        elif n % 2 == 0 or n % 3 == 0 or n % 5 == 0 or n <= 1:
    
    1010
            return False
    
    1111
        
    
    12
        a = int(n ** 0.5 / 30)
    
    12+
        sqrt_n = int(n ** 0.5 / 30)
    
    1313
        b = [7, 11, 13, 17, 19, 23, 29, 31]
    
    1414
        
    
    15
        for i in [30 * j for j in range(a + 1)]:
    
    16
            if True in [n % (i + q) == 0 for q in b if i + q is not n]:
    
    15+
        for i in (30 * k for k in range(sqrt_n + 1)):
    
    16+
            if any(n % (i + j) == 0 for j in b if i + j is not n):
    
    1717
                return False
    
    18
        return True 
    
    18+
        return True
    

Recent Moves:

Mathematics
Algorithms
Numbers

Tries make me happy.

Code
Diff
  • class ref:
        def __init__(self, data):
            self.data = data
    
    def is_happy(x, *, _trie=[False,10*[False]+[ref(True)]]+8*[False]+[ref(False)]):
        a = ref(False)
        while True:
            z = 0 # wasting some operations when x is in _trie. nobody cares though.
            t = _trie
            while x:
                r = x%10
                if not t[r]:
                    t[r] = (11-(not r))*[False]
                t = t[r]
                x //= 10
                z += r**2
            if t[-1]:
                a.data = t[-1].data
                return a.data
            t[-1] = a
            x = z
    
  • 1
    def is_happy(h: int, *, _unhappy={0}, _happy={1}) -> bool:
    
    2
        """Returns `True` if `h` is happy, `False` otherwise."""
    
    3
        seen = set()
    
    1+
    class ref:
    
    2+
        def __init__(self, data):
    
    3+
            self.data = data
    
    4+
    5+
    def is_happy(x, *, _trie=[False,10*[False]+[ref(True)]]+8*[False]+[ref(False)]):
    
    6+
        a = ref(False)
    
    44
        while True:
    
    5
            if h in _unhappy or h in seen:
    
    6
                _unhappy.update(seen)
    
    7
                return False
    
    8
            elif h in _happy:
    
    9
                _happy.update(seen)
    
    10
                return True
    
    11
            seen.add(h)
    
    12
            tot = 0
    
    13
            while h > 0:
    
    14
                tot += pow(h % 10, 2)
    
    15
                h //= 10
    
    16
            h = tot
    
    8+
            z = 0 # wasting some operations when x is in _trie. nobody cares though.
    
    9+
            t = _trie
    
    10+
            while x:
    
    11+
                r = x%10
    
    12+
                if not t[r]:
    
    13+
                    t[r] = (11-(not r))*[False]
    
    14+
                t = t[r]
    
    15+
                x //= 10
    
    16+
                z += r**2
    
    17+
            if t[-1]:
    
    18+
                a.data = t[-1].data
    
    19+
                return a.data
    
    20+
            t[-1] = a
    
    21+
            x = z
    

Recent Moves:

Code
Diff
  • using System.Linq;
    
    public class Kata
    {
      public static bool IsIsogram(string word) 
        {
            var numberOfUniqueLetters = word.ToLower().Distinct().Count();
            var areAllLettersUnique = word.Length == numberOfUniqueLetters;
            return areAllLettersUnique;
        }
    }
  • 11
    using System.Linq;
    
    22
    33
    public class Kata
    
    44
    {
    
    5
      public static bool IsIsogram(string str) => str.Length == str.ToLower().Distinct().Count();
    
    5+
      public static bool IsIsogram(string word) 
    
    6+
        {
    
    7+
            var numberOfUniqueLetters = word.ToLower().Distinct().Count();
    
    8+
            var areAllLettersUnique = word.Length == numberOfUniqueLetters;
    
    9+
            return areAllLettersUnique;
    
    10+
        }
    
    66
    }
    

Recent Moves:

Simple rainbow indentation, like you would use when writing in Python.
The second version is actually quite pointless, as I don't think Codewars users generally actually toggle the theme often, just settling on one and staying on it. Just a simple map function would probably be a lot better, as it would alter the document less to potentially break fewer scripts. That would be boring, though. It's also almost certainly possible to use low opacity to let the background's color change take care of everything, but I couldn't figure it out.
You could probably replace the current .nested-items system with <table>.

Code
Diff
  • // make it look a little nicer
    $(".title-container").css("border", "none");
    
    // too bright
    (function(xs) {
      let rainbowfy = (ix) => function() {
        $(this).css("background-color", xs[ix]); //.css("opacity", 0.5); //good if you hate using codewars
        if ($(this).hasClass("nested-items")) {
          $(this).children().each(rainbowfy((ix + 1) % xs.length));
        }
      };
      $("#snippet_list").children()
        .each(rainbowfy(0));
    })(["red", "yellow", "lime", "cyan", "blue", "magenta"]);
    
    // overcomplicated version
    (function(xs) {
      let rainbow = [[48,49,51],[228,228,231]].map(x => xs.map(y => y.map((z, i) => (z + x[i]) / 2)));
      let theme = rainbow[+!$("html").hasClass("dark")];
      let rainbowfy = (ix) => function() {
        $(this).attr("data-rainbow", ix);
        $(this).css("background-color", `rgb(${theme[ix]})`);
        if ($(this).hasClass("nested-items")) {
          $(this).children().each(rainbowfy((ix + 1) % xs.length));
        }
      };
      $("#snippet_list").children().each(rainbowfy(0));
      let colorize = function() {
        let theme = rainbow[+$("html").hasClass("dark")];
        for (let i = 0; i < xs.length; ++i) {
          $(`#snippet_list div[data-rainbow=${i}]`).css("background-color", `rgb(${theme[i]})`);
        }
      };
      $(".js-toggle-dark-mode").click(colorize);
    })([[255,0,0],[255,255,0],[0,255,0],[0,255,255],[0,0,255],[255,0,255]]);
    
  • 1
    (function(x){
    
    2
      x.src="https://code.jquery.com/jquery-3.6.0.min.js";
    
    3
      document.querySelector("head").appendChild(x);
    
    4
    })(document.createElement("script"));
    
    1+
    // make it look a little nicer
    
    2+
    $(".title-container").css("border", "none");
    
    55
    6
    $("<button>[ - - ! - - ]</button>")
    
    7
      .insertBefore(".nested-items")
    
    8
      .click(function(){$(this).next().toggle();});
    
    4+
    // too bright
    
    5+
    (function(xs) {
    
    6+
      let rainbowfy = (ix) => function() {
    
    7+
        $(this).css("background-color", xs[ix]); //.css("opacity", 0.5); //good if you hate using codewars
    
    8+
        if ($(this).hasClass("nested-items")) {
    
    9+
          $(this).children().each(rainbowfy((ix + 1) % xs.length));
    
    10+
        }
    
    11+
      };
    
    12+
      $("#snippet_list").children()
    
    13+
        .each(rainbowfy(0));
    
    14+
    })(["red", "yellow", "lime", "cyan", "blue", "magenta"]);
    
    15+
    16+
    // overcomplicated version
    
    17+
    (function(xs) {
    
    18+
      let rainbow = [[48,49,51],[228,228,231]].map(x => xs.map(y => y.map((z, i) => (z + x[i]) / 2)));
    
    19+
      let theme = rainbow[+!$("html").hasClass("dark")];
    
    20+
      let rainbowfy = (ix) => function() {
    
    21+
        $(this).attr("data-rainbow", ix);
    
    22+
        $(this).css("background-color", `rgb(${theme[ix]})`);
    
    23+
        if ($(this).hasClass("nested-items")) {
    
    24+
          $(this).children().each(rainbowfy((ix + 1) % xs.length));
    
    25+
        }
    
    26+
      };
    
    27+
      $("#snippet_list").children().each(rainbowfy(0));
    
    28+
      let colorize = function() {
    
    29+
        let theme = rainbow[+$("html").hasClass("dark")];
    
    30+
        for (let i = 0; i < xs.length; ++i) {
    
    31+
          $(`#snippet_list div[data-rainbow=${i}]`).css("background-color", `rgb(${theme[i]})`);
    
    32+
        }
    
    33+
      };
    
    34+
      $(".js-toggle-dark-mode").click(colorize);
    
    35+
    })([[255,0,0],[255,255,0],[0,255,0],[0,255,255],[0,0,255],[255,0,255]]);
    

Recent Moves: