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
Code
Diff
  • function isDivisible(n, x, y) {
      return n % x === 0 && n % y === 0;
    }
    • function isDivisible(n, x, y) {
    • if (n % x === 0 && n % y === 0) {
    • return true
    • } else {
    • return false
    • }
    • return n % x === 0 && n % y === 0;
    • }

find a creative way to return .. THE MEANING OF LIFE

your function meaning_of_life_is() should return something to explain the meaning of life.

'something' can be a string, a char, an int, or any other stuff that we may push to output stream... to get the answer!!

Code
Diff
  • constexpr int fact(int n) {
        if (n < 2) return 1;
        return n * fact(n-1);
    }
    const int HOURS_IN_A_DAY      = 24;
    const int MINUTES_IN_AN_HOUR  = 60;
    const int SECONDS_IN_A_MINUTE = 60;
    constexpr int seconds_in_a_day() { return HOURS_IN_A_DAY * MINUTES_IN_AN_HOUR * SECONDS_IN_A_MINUTE; };
    
    auto meaning_of_life_is() {
       return fact(10)/seconds_in_a_day();
    }
    • def meaning_of_life_is():
    • return """
    • go crazy with your imagination and return anything you like.
    • strings, numbers, ... just don't return None.
    • may the most creative answer win
    • """
    • constexpr int fact(int n) {
    • if (n < 2) return 1;
    • return n * fact(n-1);
    • }
    • const int HOURS_IN_A_DAY = 24;
    • const int MINUTES_IN_AN_HOUR = 60;
    • const int SECONDS_IN_A_MINUTE = 60;
    • constexpr int seconds_in_a_day() { return HOURS_IN_A_DAY * MINUTES_IN_AN_HOUR * SECONDS_IN_A_MINUTE; };
    • auto meaning_of_life_is() {
    • return fact(10)/seconds_in_a_day();
    • }
Code
Diff
  • verify_sum=lambda a,b:sum(map(ord,a))==sum(map(ord,b))if a and b else None
    • class Kata{
    • public static String verifySum(String nameOne, String nameTwo) {
    • int[] sumOfNames = new int[]{0, 0};
    • if (nameOne == null || nameTwo == null) {
    • return "NULL";
    • }
    • for (int i = 0; i < nameOne.length(); i++){
    • sumOfNames[0] += nameOne.charAt(i);
    • }
    • for (int i = 0; i < nameTwo.length(); i++){
    • sumOfNames[1] += nameTwo.charAt(i);
    • }
    • return sumOfNames[0] == sumOfNames[1] ? "TRUE" : "FALSE";
    • }
    • }
    • verify_sum=lambda a,b:sum(map(ord,a))==sum(map(ord,b))if a and b else None
Fundamentals
Code
Diff
  • def numberprint(x):
        l1 = [str(i) for i in range(1, x + 1)]
        l2 = [str(i) for i in range(x - 1, 0, -1)]
        l1 += l2
        return int("".join(l1))
    • def numberprint(x):
    • nor = 0
    • final = ''
    • while nor < x:
    • nor += 1
    • final += str(nor)
    • while nor > 1:
    • nor -= 1
    • final += str(nor)
    • return int(final)
    • l1 = [str(i) for i in range(1, x + 1)]
    • l2 = [str(i) for i in range(x - 1, 0, -1)]
    • l1 += l2
    • return int("".join(l1))
Fundamentals
Games
Code
Diff
  • def riddle(word): return word.index('?')
    • def riddle(word):
    • return len(word) - 1
    • def riddle(word): return word.index('?')
Code
Diff
  • function removeEveryThird(str) {
        return str.split('').filter((_, i) => i === 0 || i % 3 !== 0).join('');
    }
    
    • function removeEveryThird(str) {
    • return (str[0] || '') + str
    • .slice(1)
    • .replace(/(..)./g, '$1')
    • }
    • return str.split('').filter((_, i) => i === 0 || i % 3 !== 0).join('');
    • }
Mathematics
Algorithms
Logic
Numbers
Code
Diff
  • def prime_checker(n):
        if n in [2, 3, 5]:
            return True
        elif n % 2 == 0 or n % 3 == 0 or n % 5 == 0:
            return False
        
        a = int(n ** 0.5 / 30)
        b = [7, 11, 13, 17, 19, 23, 29, 31]
        
        for i in [30 * j for j in range(a + 1)]:
            if True in [n % (i + q) == 0 for q in b if i + q is not n]:
                return False
        return True 
    • """
    • https://en.wikipedia.org/wiki/Primality_test
    • This one has lesser tests or usage of % operator.
    • An alternative using primality mod 30 = 2 * 3 * 5 instead of 6 = 2 * 3
    • """
    • def prime_checker(n):
    • if n in [2, 3, 5]:
    • return True
    • elif n % 2 == 0 or n % 3 == 0 or n % 5 == 0:
    • return False
    • a = int(n ** 0.5 / 30)
    • b = [7, 11, 13, 17, 19, 23, 29, 31]
    • for i in [30 * j for j in range(a + 1)]:
    • if True in [n % (i + q) == 0 for q in b if i + q is not n]:
    • return False
    • return True
Code
Diff
  • from __future__ import annotations
    from collections import Counter
    def sort_values(vals:list[int]) -> list[int]:
        #Given an array of size N containing only 0s, 1s, and 2s; 
        #sort the array in ascending order.
        assert set(vals) <= {0,1,2}
        return counting_sort(vals)
        # O(n+k) instead of n log(n)
    
    def counting_sort(vals:list[T]) -> list[T]:
        res = []
        c = Counter(vals)
        for k,amt in sorted(c.items()):
            res += [k]*amt
        return res
    • from __future__ import annotations
    • from collections import Counter
    • def sort_values(vals:list[int]) -> list[int]:
    • #Given an array of size N containing only 0s, 1s, and 2s;
    • #sort the array in ascending order.
    • assert set(vals) <= {0,1,2}
    • return counting_sort(vals)
    • # O(n+k) instead of n log(n)
    • def counting_sort(vals:list[T]) -> list[T]:
    • res = []
    • c = Counter(vals)
    • for k,amt in sorted(c.items()):
    • res += [k]*amt
    • return res
Code
Diff
  • module Knot where
    onesAndZeroes=cycle [1,0]
    • module Knot where
    • onesAndZeroes=map(flip mod 2)[1..]
    • onesAndZeroes=cycle [1,0]
Code
Diff
  • const code = String.raw`
    Y = \ f . ( \ x . f (x x) ) ( \ x . f (x x) )
    True = \ t f . t
    False = \ t f . f
    Succ = \ n s z . s (n s z)
    Pred = \ n s z . n ( \ f g . g (f s) ) (\_.z) \x.x
    Minus = \ m n . n Pred m
    Times = \ m n s . m (n s)
    isZero = \ n . n (\_.False) True
    isNotZero = \ n . n (\_.True) False
    And = \ x y . x y x
    Or = \ x . x x
    GT = \ x y . isNotZero (Minus x y)
    Mod = \ n m . ( \ r . isZero (Minus m r) 0 r ) (( \ n m . ( \ d . isZero d n (Mod d m) ) (Minus n m) ) n m)
    
    # function isPrime(n) {
    #   const trial = function trial(i) {
    #     return i * i > n || n % i != 0 && trial(i+1) ;
    #   } ;
    #   return n > 1 && trial(2) ;
    # }
    
    isPrime = \ n . ( \ trial . And (GT n 1) (trial 2) )
                    ( Y \ trial i . Or (GT (Times i i) n) (And (isNotZero (Mod n i)) (trial (Succ i))) )
    `
    • const code = String.raw`
    • succ = \ n f x . f (n f x)
    • pair = \a.\b.\c.c a b
    • fst = \pair.pair (\a.\_.a)
    • snd = \pair.pair (\_.\b.b)
    • plus = \pair.\f.\x.(fst pair) f ((snd pair) f x)
    • next = \prev.pair (snd prev) (plus prev)
    • fibonacci = \n. fst (n next (pair (\_.\b.b) (succ (\_.\b.b))))
    • `
    • Y = \ f . ( \ x . f (x x) ) ( \ x . f (x x) )
    • True = \ t f . t
    • False = \ t f . f
    • Succ = \ n s z . s (n s z)
    • Pred = \ n s z . n ( \ f g . g (f s) ) (\_.z) \x.x
    • Minus = \ m n . n Pred m
    • Times = \ m n s . m (n s)
    • isZero = \ n . n (\_.False) True
    • isNotZero = \ n . n (\_.True) False
    • And = \ x y . x y x
    • Or = \ x . x x
    • GT = \ x y . isNotZero (Minus x y)
    • Mod = \ n m . ( \ r . isZero (Minus m r) 0 r ) (( \ n m . ( \ d . isZero d n (Mod d m) ) (Minus n m) ) n m)
    • // Stress testing -- "LetRec", "BinaryScott"
    • // Testing implementation of a "String" - ie. Arrays and related functions
    • const stress = String.raw`
    • # bools
    • id = \ x . x
    • true = \ a b . a
    • false = \ a b . b
    • not = \ b . b false true
    • and = \ a b . a b false
    • or = \ a b . a true b
    • xor = \ a b . a (b false true) b
    • # function isPrime(n) {
    • # const trial = function trial(i) {
    • # return i * i > n || n % i != 0 && trial(i+1) ;
    • # } ;
    • # return n > 1 && trial(2) ;
    • # }
    • # ints -- z = endbit, f = offbit, t = onbit
    • zero = \ z _ _ . z
    • succ = \ n _ f t . n (t zero) t (\ m . f (succ m))
    • bool = \ n . n false (\ _ . true) (\ _ . true)
    • pred = \ n z f t . n z (\ m . t (pred m)) (\ m . bool m (f m) z)
    • odd = \ n . n false false true
    • even = \ n . not (odd n)
    • mul2 = \ n _ f _ . f n
    • addSlow = \ a b . bool b (addSlow (succ a) (pred b)) a
    • subSlow = \ a b . bool a (bool b (subSlow (pred a) (pred b)) a) (zero)
    • # arrays as foldr (strings)
    • isPrime = \ n . ( \ trial . And (GT n 1) (trial 2) )
    • ( Y \ trial i . Or (GT (Times i i) n) (And (isNotZero (Mod n i)) (trial (Succ i))) )
    • `