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

We have n different groups of elements and we want to know all the possible combinations of n elements from these groups.
Each combinations should be formed having one element from each group.
The function generates all the possible different combinations.

def groups_combination_(a)
	  a[1..-1].inject(a[0]){ |m,v| m = m.product(v).map(&:flatten) }
end

def groups_combinations(arr2D)
    res = groups_combination_(arr2D)
    return [res.length, res]
end

We have n different groups of elements and we want to know all the possible combinations of n elements from these groups.
Each combinations should be formed having one element from each group.
The function generates all the possible different combinations.

function groupCombinations_() {
    var r = [], arg = arguments, max = arg.length-1;
    function helper(arr, i) {
        for (var j=0, l=arg[i].length; j<l; j++) {
            var a = arr.slice(0); 
            a.push(arg[i][j]);
            if (i==max)
                r.push(a);
            else
                helper(a, i+1);
        }
    }
    helper([], 0);
    return r;
}

function groupCombinations(arr2D) {
    var combL = groupCombinations_.apply(this, arr2D);
    return [combL.length, combL];
}

you will be given a sentence and a set of letters the program should test for the amount of letters in the sentence

EXAMPLE: sentence: "only one z and two w's" letters: ["z","w"] expected: [1,2]

function testAmount(sentence,letters){
 var a=[];
 for(var i=0;i<letters.length;i++){
     a.push(0);
   for(var j=0;j<sentence.length;j++){
     if(sentence[j] == letters[i]){
       a[i]++;
     }
   }
 }
 return a;
}

Javascript version of fast code to get all the proper factors of a number

var sortNumber = function(a, b){return a - b;};

function getDiv(n){
    var factL= [], i;
    for (i = 1; i <= Math.floor(Math.sqrt(n)); i += 1) {
        if (n % i === 0) {
            factL.push(i);
            if (n / i !== i) factL.push(n / i);
        }
    }
    factL.sort(sortNumber);
    return factL;
}
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();
  }
}