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
Fundamentals

I tried to make it as readable a possible without comments.

Code
Diff
  • def numberprint(peak):
        up = ''.join(map(str, range(1,peak)))
        down = up[::-1]
    
        return int(up + str(peak) + down)
    
    • 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)
    • def numberprint(peak):
    • up = ''.join(map(str, range(1,peak)))
    • down = up[::-1]
    • return int(up + str(peak) + down)
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
  • meaning_of_life_is = lambda:__import__('this')
    • def meaning_of_life_is():
    • def zen():
    • import this
    • return str(zen())
    • meaning_of_life_is = lambda:__import__('this')

Kumite page 1 is a little lonely.
I feel like there is a lot that can be chopped off from this, may revisit later.

Code
Diff
  • f(r,n)=r^r<n ? -1 : r<2 ? 1 : parse(Int,lpad(h(r,n-1),r,"1"));h(r,n)=n<1 ? 0 : 10h(r,n÷r)+n%r+1
    • using System;
    • using System.Linq;
    • using System.Collections.Generic;
    • public class NumbersFinder
    • {
    • public static int Generator(int size , int position){
    • if ( Math.Pow( size , size ) < position )
    • return -1;
    • List<string> arr = new List<string>();
    • for (int i = 0; i < size; ++i)
    • arr.Add((i+1).ToString());
    • List<string> newArr;
    • while (arr.Count != Math.Pow(size,size)){
    • newArr = new List<string>();
    • for (int j = 0; j < arr.Count; j++)
    • for (int i = 0; i < size; i++)
    • newArr.Add(arr[j]+(i+1));
    • arr.Clear();
    • arr.AddRange(newArr);
    • }
    • return Convert.ToInt32(arr[position - 1]);
    • }
    • }
    • f(r,n)=r^r<n ? -1 : r<2 ? 1 : parse(Int,lpad(h(r,n-1),r,"1"));h(r,n)=n<1 ? 0 : 10h(r,n÷r)+n%r+1
Code
Diff
  • let ReverseInt x =
      let rec ReverseInt'(acc, x) =
        match System.Math.DivRem(x, 10) with
        | (0, rem) -> 10 * acc + rem
        | (quot, rem) -> ReverseInt'(10 * acc + rem, quot)
      match System.Math.DivRem(x, 10) with
      | (0, rem) -> rem
      | (quot, rem) -> ReverseInt'(rem, quot)
    ;;
      
    • public class Algorithms {
    • public static int reverseInt(int n) {
    • int reversed = 0;
    • while(n != 0){
    • reversed = reversed * 10 + (n % 10);
    • n /= 10;
    • }
    • return reversed;
    • }
    • }
    • let ReverseInt x =
    • let rec ReverseInt'(acc, x) =
    • match System.Math.DivRem(x, 10) with
    • | (0, rem) -> 10 * acc + rem
    • | (quot, rem) -> ReverseInt'(10 * acc + rem, quot)
    • match System.Math.DivRem(x, 10) with
    • | (0, rem) -> rem
    • | (quot, rem) -> ReverseInt'(rem, quot)
    • ;;
Games
Arrays
Data Types
Algorithms
Logic
Code
Diff
  • calculating_the_amount_energy=\
    lambda c:sum(abs(c[n]-c[n+1])for n in range(len(c)-1))
    • using System;
    • public static class Kata
    • {
    • public static int CalculatingTheAmountEnergy(int[] coordinates)
    • {
    • // here's your code
    • }
    • }
    • calculating_the_amount_energy=\
    • lambda c:sum(abs(c[n]-c[n+1])for n in range(len(c)-1))
Numbers
Data Types
Integers
Algorithms
Logic

Please never actually use this method of counting digits.

Code
Diff
  • #include <stdint.h>
    
    uint_fast8_t number_of_digits(uint64_t n)
    {
        return printf("%lu", n);
    }
    • fn digits(mut n: u64) -> usize {
    • let mut l = 1;
    • while n >= 10 {
    • n /= 10;
    • l += 1;
    • }
    • l
    • #include <stdint.h>
    • uint_fast8_t number_of_digits(uint64_t n)
    • {
    • return printf("%lu", n);
    • }
Fundamentals
Numbers
Data Types
Integers

Ternary opertor FTW.

Code
Diff
  • public static class Kata
    {
        public static bool IsOdd(int input)
        {
            return input % 2 != 0 ? true : false;
        }
    }
    • public static class Kata
    • {
    • public static bool IsOdd(int input)
    • {
    • return ((input % 10 == 1) || (input % 10 == 3) || (input % 10 == 5) || (input % 10 == 7) || (input % 10 == 9));
    • return input % 2 != 0 ? true : false;
    • }
    • }
Code
Diff
  • import functools
    find_max = lambda arr:functools.reduce(lambda x,y:x if x > y else y,arr)
    • def find_max(arr):
    • return 0
    • import functools
    • find_max = lambda arr:functools.reduce(lambda x,y:x if x > y else y,arr)