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
  • using System;
    
    namespace Solution {
    
      class FizzBuzz {
        public static string Convert(int input)
            {
                var divisableBy3 = input % 3 == 0;
                var divisableBy5 = input % 5 == 0;
                
                return (!divisableBy3 & !divisableBy5) ? input.ToString()
                  : (divisableBy3 ? "Fizz" : string.Empty) +  (divisableBy5 ? "Buzz" : string.Empty);
            }
      }
    }
    • using System;
    • namespace Solution {
    • class FizzBuzz {
    • public static string Convert(int input)
    • {
    • var divisableBy3 = (input % 3 == 0);
    • var divisableBy5 = (input % 5 == 0);
    • var divisableBy3 = input % 3 == 0;
    • var divisableBy5 = input % 5 == 0;
    • return (!divisableBy3 & !divisableBy5) ? input.ToString()
    • : (divisableBy3 ? "Fizz" : string.Empty) + (divisableBy5 ? "Buzz" : string.Empty);
    • }
    • }
    • }
Testing
Code
Diff
  • def replicate(times, num):
        if times <= 0: return []
        return [num] + replicate(times-1, num)
    
    replicate(8,5)
    • def replicate(times, num):
    • if times <= 0: return []
    • return [num] + replicate(times-1, num)
    • return [num] + replicate(times-1, num)
    • replicate(8,5)
Code
Diff
  • import java.util.stream.IntStream;
    
    public class Area {
    
      public static long[] workOutArea(final long[] values){
        return values.length % 2 != 0? null: IntStream.range(0, values.length).filter(x -> x % 2 == 0).mapToLong(x -> values[x] * values[x+1]).toArray();
      }
    
    }
    • import java.util.stream.IntStream;
    • public class Area {
    • public static long[] workOutArea(final long[] values){
    • if (values.length % 2 != 0) {
    • return null; // This is ugly!
    • } else {
    • final long[] areas = new long[values.length / 2];
    • for (int i = 0; i < values.length; i += 2) {
    • areas[i / 2] = values[i] * values[i + 1];
    • }
    • return areas;
    • }
    • return values.length % 2 != 0? null: IntStream.range(0, values.length).filter(x -> x % 2 == 0).mapToLong(x -> values[x] * values[x+1]).toArray();
    • }
    • }

Show optimization of code. Instead 4 passs throught array (max,min,count double time), use only one pass durring sorting.

Code
Diff
  • # Find stray number
    def find_stray(n)
      n.count(n.min) > n.count(n.max) ? n.max : n.min
    end
    
    # Find stray optimization
    def find_stray_o(n)
      n.sort!
      n[0] == n[1] ? n[-1] : n[0]
    end
    
    require "benchmark"
    
    array = (Array.new(1000_000,7) + [1]).shuffle
    
    Benchmark.bm(10) do |x|
      x.report("Find stray") { 10.times{ find_stray(array.clone.shuffle) }}
      x.report("Optimized") { 10.times{find_stray_o(array.clone.shuffle) }}
    end
    • # Find stray number
    • def find_stray(n)
    • n.count(n.min) > n.count(n.max) ? n.max : n.min
    • end
    • # Find stray optimization
    • def find_stray_o(n)
    • n.sort!
    • n[0] == n[1] ? n[-1] : n[0]
    • end
    • require "benchmark"
    • array = (Array.new(1000_000,7) + [1]).shuffle
    • Benchmark.bm(10) do |x|
    • x.report("Find stray") { 10.times{ find_stray(array.clone.shuffle) }}
    • x.report("Optimized") { 10.times{find_stray_o(array.clone.shuffle) }}
    • end
Code
Diff
  • ++++++[>++++++<-]>[->+>++>+++>+++<<<<]>>.>-------.>..+++.<<<----.>-.>----.+.>+++.<+++++++.----.>------.
    • -[------->+<]>-.-[->+++++<]>++.+++++++..+++.[--->+<]>-----.+++[->++<]>+.-[------>+<]>.+.[--->+<]>----.---------.----.+++++++.
    • +++++++[>++++++<-]>[->+>++>+++>+++<<<<]>>.>-------.>..+++.<<<----.>-.>----.+.>+++.<+++++++.----.>------.

Missing what is it about. Just simplyfing things :)

Code
Diff
  • COLORS = set("RGB")
    def blend(c1, c2):
        colors = {c1, c2}
        return c1 if len(colors) == 1 else (COLORS - colors).pop()
    
    
    def preprocess(row):
        check = ""
        for r in row:
            if r != check:
                yield r
                check = r
    
    
    def triangle(row):
        row = list(preprocess(row))
        while len(row) > 1:
            for i,r in enumerate(row[:-1]):
                row[i] = blend(r, row[i+1])
            row.pop()
        return row[0]
    
    • import re
    • COLORS = set("RGB")
    • def blend(c1, c2):
    • if c1 == c2: return c1
    • colors = c1 + c2
    • if colors == "RB" or colors == "BR": return "G"
    • if colors == "RG" or colors == "GR": return "B"
    • if colors == "GB" or colors == "BG": return "R"
    • colors = {c1, c2}
    • return c1 if len(colors) == 1 else (COLORS - colors).pop()
    • def preprocess(row):
    • orig = row
    • row,_ = re.subn('RR+', 'R', row)
    • row,_ = re.subn('BB+', 'B', row)
    • row,_ = re.subn('GG+', 'G', row)
    • print(orig, row)
    • return row
    • check = ""
    • for r in row:
    • if r != check:
    • yield r
    • check = r
    • def triangle(row):
    • if len(row) == 1: return row
    • row = preprocess(row)
    • row = list(row)
    • for j in range(len(row)-1,0,-1):
    • for i in range(j):
    • row[i] = blend(row[i], row[i+1])
    • return row[0]
    • row = list(preprocess(row))
    • while len(row) > 1:
    • for i,r in enumerate(row[:-1]):
    • row[i] = blend(r, row[i+1])
    • row.pop()
    • return row[0]

Looks familiar?

Expected: equal to [unsupported type]
Actual: [unsupported type]

No more!

Code
Diff
  • template <class... Args>
    bool alwaysTrue(Args&&...) {
      return true;
    }
    
    template <class T>
    T id(T&& x)  {
      return x;
    }
    
    • template <class... Args>
    • bool alwaysTrue(Args&&...) {
    • return true;
    • }
    • }
    • template <class T>
    • T id(T&& x) {
    • return x;
    • }