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

If you could not tell, I am very inexperienced in Ruby.
My easiest golf Kumite to beat by far.

Code
Diff
  • def f r,n;r**r<n ?-1: r<2?1:(n-1).to_s(r).chars.map{|x|x.to_i+1}.reduce{|c,x|10*c+x}end
    • 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]);
    • }
    • }
    • def f r,n;r**r<n ?-1: r<2?1:(n-1).to_s(r).chars.map{|x|x.to_i+1}.reduce{|c,x|10*c+x}end
Strings
Data Types
Code
Diff
  • module Format where
    
    import Data.Bits ((.|.))
    import Data.Char (chr)
    
    f :: Integer -> [Char]
    f n = f' [chr $ (.|.) 48 $ fromIntegral $ mod n 10] (div n 10) where
      f' :: [Char] -> Integer -> [Char]
      f' sol 0 = sol
      f' acc n = f'' ((:) (chr $ (.|.) 48 $ fromIntegral $ mod n 10) acc) (div n 10) where
        f'' :: [Char] -> Integer -> [Char]
        f'' sol 0 = sol
        f'' acc n = f''' ((:) (chr $ (.|.) 48 $ fromIntegral $ mod n 10) acc) (div n 10) where
          f''' :: [Char] -> Integer -> [Char]
          f''' sol 0 = sol
          f''' acc n = f' ((:) (chr $ (.|.) 48 $ fromIntegral $ mod n 10) $ (:) ',' acc) (div n 10) 
    • def f(n):
    • G = 3
    • s = str(n)
    • r = len(s) % G
    • def make(s):
    • if r:
    • yield s[:r]
    • for i in range(r, len(s), G):
    • yield s[i:i+G]
    • return ','.join(make(s))
    • module Format where
    • import Data.Bits ((.|.))
    • import Data.Char (chr)
    • f :: Integer -> [Char]
    • f n = f' [chr $ (.|.) 48 $ fromIntegral $ mod n 10] (div n 10) where
    • f' :: [Char] -> Integer -> [Char]
    • f' sol 0 = sol
    • f' acc n = f'' ((:) (chr $ (.|.) 48 $ fromIntegral $ mod n 10) acc) (div n 10) where
    • f'' :: [Char] -> Integer -> [Char]
    • f'' sol 0 = sol
    • f'' acc n = f''' ((:) (chr $ (.|.) 48 $ fromIntegral $ mod n 10) acc) (div n 10) where
    • f''' :: [Char] -> Integer -> [Char]
    • f''' sol 0 = sol
    • f''' acc n = f' ((:) (chr $ (.|.) 48 $ fromIntegral $ mod n 10) $ (:) ',' acc) (div n 10)

The same thing as my C solution, just more Pythonic because it is written in Python.

Code
Diff
  • def reverse_int(int_reverse: int) -> int:
        div_mod: (int, int) = divmod(int_reverse, 10)
        reverse_int: int = div_mod[1]
        while div_mod[0]:
            div_mod = divmod(div_mod[0], 10)
            reverse_int *= 10
            reverse_int += div_mod[1]
        return reverse_int
    • public class Algorithms {
    • public static int reverseInt(int n) {
    • int reversed = 0;
    • while(n != 0){
    • reversed = reversed * 10 + (n % 10);
    • n /= 10;
    • }
    • return reversed;
    • }
    • }
    • def reverse_int(int_reverse: int) -> int:
    • div_mod: (int, int) = divmod(int_reverse, 10)
    • reverse_int: int = div_mod[1]
    • while div_mod[0]:
    • div_mod = divmod(div_mod[0], 10)
    • reverse_int *= 10
    • reverse_int += div_mod[1]
    • return reverse_int
Games
Arrays
Data Types
Algorithms
Logic

A new approach to a trivial problem.
Also added a few testcases.

Code
Diff
  • (* *)
    let (<<) f g x = f @@ g x ;;
    
    let platforms xs =
      let rec platforms' (acc, xs) = 
        match xs with
        | x::[] -> acc x
        | x::xs'-> platforms' ((+) @@ acc x << abs << (-) x, xs')
        | [] -> failwith "only exists to make the compiler shut up"
      in
      match xs with
      | []
      | _::[] -> 0
      | x::xs' -> platforms' (abs << (-) x, xs')
    ;;
    
    • using System;
    • public static class Kata
    • {
    • public static int CalculatingTheAmountEnergy(int[] coordinates)
    • {
    • // here's your code
    • }
    • }
    • (* *)
    • let (<<) f g x = f @@ g x ;;
    • let platforms xs =
    • let rec platforms' (acc, xs) =
    • match xs with
    • | x::[] -> acc x
    • | x::xs'-> platforms' ((+) @@ acc x << abs << (-) x, xs')
    • | [] -> failwith "only exists to make the compiler shut up"
    • in
    • match xs with
    • | []
    • | _::[] -> 0
    • | x::xs' -> platforms' (abs << (-) x, xs')
    • ;;
Fundamentals
Numbers
Data Types
Integers
Code
Diff
  • public static class Kata
    {
        public static bool IsOdd(int input)
        {
            return (input % 2 != 0);
        }
    }
    • 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);
    • }
    • }
Code
Diff
  • using System;
    
    class Kata
    {
        public static void Main()
        {
            Console.WriteLine("Hello, C#!");
        }
    }
    • using System;
    • class Kata
    • {
    • public static void Main()
    • {
    • string greeting = "Hello";
    • string language = "C#";
    • Console.WriteLine($"{greeting}, {language}!");
    • Console.WriteLine("Hello, C#!");
    • }
    • }
Numbers
Data Types
Integers
Algorithms
Logic

Determine the number of digits in a chosen base using an iterator

Code
Diff
  • fn digits(n: u64, base: u64) -> usize {
        DigitIterator::new(n, base).count()
    }
    
    struct DigitIterator{
        value: u64,
        base: u64,
        is_0: bool,
        first_iter: bool
    }
    
    impl DigitIterator{
        pub fn new(value: u64, base: u64) -> Self{
            Self{
                value,
                base,
                is_0: value == 0,
                first_iter: true,
            }
        }
    }
    
    impl Iterator for DigitIterator{
        type Item = u64;
        
        fn next(&mut self) -> Option<u64>{
            if self.is_0 {
                if self.first_iter{
                    self.first_iter = false;
                    Some(0)
                }else{
                    None
                }
            }else{
                let old = self.value;
                self.value /= self.base;
                if old != 0{
                    Some(old % self.base)
                }else{
                    None
                }
            }
        }
    }
    • fn digits(mut n: u64) -> usize {
    • let mut l = 1;
    • while n >= 10 {
    • n /= 10;
    • l += 1;
    • fn digits(n: u64, base: u64) -> usize {
    • DigitIterator::new(n, base).count()
    • }
    • struct DigitIterator{
    • value: u64,
    • base: u64,
    • is_0: bool,
    • first_iter: bool
    • }
    • impl DigitIterator{
    • pub fn new(value: u64, base: u64) -> Self{
    • Self{
    • value,
    • base,
    • is_0: value == 0,
    • first_iter: true,
    • }
    • }
    • }
    • impl Iterator for DigitIterator{
    • type Item = u64;
    • fn next(&mut self) -> Option<u64>{
    • if self.is_0 {
    • if self.first_iter{
    • self.first_iter = false;
    • Some(0)
    • }else{
    • None
    • }
    • }else{
    • let old = self.value;
    • self.value /= self.base;
    • if old != 0{
    • Some(old % self.base)
    • }else{
    • None
    • }
    • }
    • }
    • l
    • }
Code
Diff
  • def find_max(arr):
        return sorted(arr)[-1]
    • def find_max(arr):
    • return 0
    • return sorted(arr)[-1]
Code
Diff
  • print('hello world')
    • print ('hello world)
    • print('hello world')