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
Algorithms
Logic

The fastest way to find all dividors of a number.

const getDividors = (n, result = []) => {   

  for (let i = 1; i <= Math.floor(Math.sqrt(n)); i++)
    if (n % i === 0) { result.push(i); if (n / i !== i) result.push(n / i) }
    
  return result; // output array won't be sorted
  
}
let projectEulerProblemOne = [1 .. 999] |> List.filter(fun x -> x % 3 = 0 || x % 5 = 0) |> List.sum
class Human {
  constructor (firstName, lastName) {
    this.firstName = firstName || ""
    this.lastName = lastName || ""
  }
  filterMyFamily(humans) {
    return humans.filter(human => (human.lastName == this.lastName))
  }
}

Test output documentation: https://github.com/Codewars/codewars-runner-cli/blob/00a657c99f347ef8ecb075b8a19ebab7d8fc1535/documentation/output_format.md#nested-describes

If you print '<COMPLETEDIN::>' after a Test.describe() or Test.it(), you can close describe/it groupings and have a nested structure like you can for the other languages.

def hi():
    return 'hi'


# https://github.com/Codewars/codewars-runner-cli/blob/00a657c99f347ef8ecb075b8a19ebab7d8fc1535/documentation/output_format.md#nested-describes
# use this to close Test.describe and Test.it groupings
def close_group():
    print('<COMPLETEDIN::>')


close_describe = close_it = close_group;

Any help is welcome :)

import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created by Javatlacati on 07/02/2017.
 */
public class ThreadIssueSolution extends ScheduledThreadPoolExecutor {
    public boolean isUsable=true;
    public ThreadIssueSolution() {
        super(1);
    }

    @Override
    public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
        return super.scheduleAtFixedRate(wrapRunnable(command), initialDelay, period, unit);
    }

    @Override
    public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
        return super.scheduleWithFixedDelay(wrapRunnable(command), initialDelay, delay, unit);
    }

    private Runnable wrapRunnable(Runnable command) {
        return new LogOnExceptionRunnable(command);
    }

    @Override
    protected void afterExecute(Runnable r, Throwable t) {
//        super.afterExecute(r, t);
        if(!(t == null && r == null)){
            throw new ArithmeticException("ooops");
        }
    }

    private class LogOnExceptionRunnable implements Runnable {
        private Runnable theRunnable;

        public LogOnExceptionRunnable(Runnable theRunnable) {
            super();
            this.theRunnable = theRunnable;
        }

        @Override
        public void run() {
            try {
                theRunnable.run();
            } catch (Throwable e) {
               System.err.println("error ejecutando: " + theRunnable + ". no seguirá corriendo!");
                //e.printStackTrace();
                // and re throw it so that the Executor also gets this error so that it can do what it would
                // usually do
                throw new RuntimeException(e);
            }
        }
    }
}

That's a simple threading test using JavaFX. It currently has troubles due to codewars JVM runner.

import java.util.concurrent.atomic.AtomicInteger;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.stage.Stage;

/** Created by Javatlacati on 08/02/2017. */
public class Aciago extends Application {
  public static void main(String[] args) {
    launch(args);
  }

  @Override
  public void start(Stage primaryStage) throws Exception {
    Thread miHilo =
        new Thread(
            new Runnable() {
              final AtomicInteger i = new AtomicInteger(0);

              @Override
              public void run() {
                System.out.println("Corriendo");
                while (true) {
                  Platform.runLater(
                      new Runnable() {
                        @Override
                        public void run() {
                          System.out.println(i.getAndIncrement() + " ola soi un hilo :v");
                        }
                      });

                  try {
                    if (i.get() < 4) {
                      System.out.println("anuma me voi a dormir");
                      Thread.sleep(1000);
                    } else {
                      throw new InterruptedException("#PosMeMuero");
                    }
                  } catch (InterruptedException ex) {
                    System.err.println("#ToyMorido");
                    Platform.exit();
                    System.out.println("JavaFx is dead");
                    break;
                  }
                }
              }
            });

    miHilo.setName("soy el mapa soy el mapa soy el mapa soy el mapa soy el mapa!");
    miHilo.setDaemon(false);
    miHilo.start();
  }
}

Calculated the combinations https://en.wikipedia.org/wiki/Combination

module NCR where

--Combinations nCr
comb:: Integer -> Integer -> Integer
comb n r | n/=r = (foldl (*) 1 [1..n]) `div` ((foldl  (*) 1 [1..r]) * (foldl (*) 1 [1..(n-r)]))
         | n==r = (foldl (*) 1 [1..n]) `div` ((foldl  (*) 1 [1..r]))
user2514386Failed Tests

Quine

This is a quine in Python 2 (Will not work in 3).

_='_=%r;print _%%_';print _%_

A really arcaic calculator for pi, that takes ages to get a little precision.

var ex431 = function(tries){
    var inc=0, outc=0, x, y;
    
    while(tries>0){
        x =  Math.random();
        y =  Math.random();
        
        if (x*x + y*y <= 1) inc++;
        else outc++;
        tries--;
    }
    return inc/(inc+outc);
}

I needed to iterate a block on a value n times and return the value to solve a kata. Getting f(f(..f(x)..)) applying f n times. This is the trivial solution:

n.times do
  x = f.call(x)
end
return x

As times returns n rather than anything in the block a separate return x is needed after the block. Also x = modified x is needed. Wouldn't it be nice to have something built in for this purpose? like

x.modify(n, &block)

It turns out that we can achieve something pretty close to this with the built in inject. As times without a block returns an Enumerator, as most Enumerable functions do, (yielding increasing numbers), with the daisy chaining of Enumerables, using only the accumulator of inject this works fine:

n.times.inject(x) { |x| block.call(x) }

However this doesn't work :( as inject in this case feeds in the index:

n.times.inject(x, &block)
class Object
  def modify(n)
    return to_enum :modify unless block_given?
    case n
    when Enumerator then n.each.inject(self) { |acc| yield(acc) }
    when Numeric    then n.times.inject(self) { |acc| yield(acc) }
    end    
  end
end

p 5.modify 2.times, &:~@ # flipping bits twice