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

A little help for claculate the distances between two points in a plane(2D case) and in the space (3D case)

from math import sqrt

def distance2D(pA, pB):
    if pA == pB: return 0
    xA, yA = tuple(pA); xB, yB = tuple(pB)
    return sqrt((xA - xB)**2 + (yA - yB)**2)
    
def distance3D(pA, pB):
    if pA == pB: return 0
    xA, yA, zA = tuple(pA); xB, yB, zB = tuple(pB)
    return sqrt((xA - xB)**2 + (yA - yB)**2 + (zA - zB) **2)

A little help for claculate the distances between two points in a plane(2D cases) and in the space (3D cases)

def distance2D(pA, pB)
    return 0 if pA == pB
    xA = pA[0]; yA = pA[1]; xB= pB[0]; yB = pB[1]
    return Math.sqrt((xA - xB)**2 + (yA - yB)**2)
end
    
def distance3D(pA, pB)
    return 0 if pA == pB
    xA = pA[0]; yA = pA[1]; zA = pA[2]; xB= pB[0]; yB = pB[1]; zB = pB[2]
    return Math.sqrt((xA - xB)**2 + (yA - yB)**2 + (zA - zB) **2)
end  

def range (min, max)
    rand * (max-min) + min
end

A little help to calculate the distances between two points in a plane(2D cases) and in the space (3D cases)

function distance2D(pA, pB) {
    if (pA == pB) return 0;
    var xA = pA[0], yA = pA[1], xB= pB[0], yB = pB[1];
    return Math.sqrt((xA - xB)**2 + (yA - yB)**2)
}
    
function distance3D(pA, pB) {
    if (pA == pB) return 0;
    var xA = pA[0], yA = pA[1], zA = pA[2], xB= pB[0], yB = pB[1], zB = pB[2];
    return Math.sqrt((xA - xB)**2 + (yA - yB)**2 + (zA - zB) **2);
}

String.split Demo:

'123456'.split('');

// [ '1', '2', '3', '4', '5', '6' ]

How about:

'123456'.spliter(2);
// [ '12', '34', '56' ]

?

console.log(
  '123456'.split('')
);
Strings
Data Types

Let's try to grab the last character from a string.

def last_char(str):
  return str[-1]

This is my Pretty Print code for the Airport Arrivals/Departures flap display

Ref: https://www.codewars.com/kata/airport-arrivals-slash-departures-number-1/java

public class Dinglemouse {

  // Use CSS to display a pretty version of the flap display
  // From: https://www.codewars.com/kata/airport-arrivals-slash-departures-number-1/java
  public static String[] prettyPrint(final String[] lines) {
    String s = "<pre>";
    for (int y = 0; y < lines.length; y++) {
      s += "<div style=\"height:23px\">";
      for (int x = 0; x < lines[y].length(); x++) {
        s += "<span style=\"font-size:10px;color:yellow;padding:5px;border:1px solid gray;background:black\">"+lines[y].charAt(x)+"</span>";
      }
      s += "</div>";
    }
    s+= "</pre>";
    System.out.println(s);
    return lines;
  }

}

A very fast code to test if a number is a prime. You can see its performance having 100 tests from 1000 to 10e12 in less than 3000 ms

from math import sqrt
def is_prime(n):
    if n < 2: return False
    for x in range(2, int(sqrt(n)) + 1):
        if n % x == 0: return False
    return True

A very fast code to test if a number is a prime. You can see its performance having 100 tests from 1000 to 10e12 in less than 1000 ms

function isPrime(n) {
    if (n < 2) return false;
    for (var x = 2; x <= Math.floor(Math.sqrt(n)); x++) {if (n % x == 0) return false;}
    return true;
}

A very fast code to test if a number is a prime. You can see its performance having 100 tests from 1000 to 10e12 in less than 1000 ms

def is_prime(n)
    return false if n < 2
    for x in 2.. Math.sqrt(n).round
        return false if n % x == 0
    end
    return true
end

I received a fork to my version in python by the user Mc Code. The average runtime for different tries is under 500 ms. The half runtime that the previous version in Javascript, too (1000 ms)

function isPrime(n) {
    if (n < 2) return false;
    else if (n == 2) return true;
    else if (n % 2 === 0) return false;
    for (var x = 3; x <= Math.floor(Math.sqrt(n)); x += 2) {if (n % x === 0) return false;}
    return true;
}