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

The goal is to estimate Pi using a Monte Carlo approach. In the 18th century, French mathematician Georges-Louis Leclerc, Comte de Buffon approximated pi by simulating throwing needles within a square that contained a circle with a diameter equal to the side of the square, and calculating the probability that they will end up in the circle.

The idea is that the ratio of needles inside the circle versus needles in the square is the same as the ratio of the area of the circle versus the area of the square.

If we use a square with a side equal to 2, its area is 4. The circle inside the square will have a diameter of 2 (therefore a radius of 1), and its area will be Pi * R**2 = Pi * 1 = Pi. So Pi / 4 = (number of needles inside the circle) / (number of needles inside the square). which means

Pi = 4 * (number of needles inside the circle) / (number of needles inside the square)

To estimate Pi, you need to randomly throw dots (same thing as a needle) in a 2 x 2 square and count the ones that will end up in the inner circle. Test with 2 millions random dots to get a fairly good estimate of Pi.

import random
def PiEstimate(runs):
    random.seed(0)   
    inner = 0
    for i in range(n):
        if random.random()**2 + random.random()**2 < 1:
            inner += 1
    return 4 * (inner / n)

Here's an algorithm to simplify a fraction (i.e. reduce a fraction to its lowest terms). It is written in Javascript for simplicity, but it's easily translatable to any programming language.

// e.g.:
// simplify( 15,   5) == [  3,  1]
// simplify(-50,  20) == [- 5,  2]
// simplify( 20, - 2) == [-10,  1]
// simplify(- 6, - 3) == [  2,  1]
// simplify(- 0,   3) == [  0,  1]
// simplify(  0,   0) == undefined
// simplify(  5, - 0) == undefined

function simplify(n, d){
  if (d === 0){
    return undefined;
  }

  // fraction_sign contains the sign of the fraction (1 if positive, -1 if negative)
  const fraction_sign = ((n < 0) ? -1 : 1) * ((d < 0) ? -1 : 1);
  // fraction_gcd contains the greatest common divisor of n and d
  const fraction_gcd = gcd(Math.abs(n), Math.abs(d));
  // we calculate the reduced numerator (it has the same sign as the fraction)
  const result_n = fraction_sign * Math.abs(n) / fraction_gcd;
  // we calculate the reduced denominator
  const result_d = Math.abs(d) / fraction_gcd;

  return [result_n, result_d];
}



// gcd(x, y) calculates the greatest common divisor of x and y
// x and y must be non-negative integers
// USED ALGORITHM: binary method
// BASED ON: https://en.wikipedia.org/wiki/Binary_GCD_algorithm

function gcd(x, y){
  if (x === y){
    return x;
  }

  if (x === 0){
    return y;
  }

  if (y === 0){
    return x;
  }

  if (x % 2 === 0){
    if (y % 2 === 1){
      return gcd(x >> 1, y);
    }
    else {
      return gcd(x >> 1, y >> 1) << 1;
    }
  }

  if (y % 2 === 0){
    return gcd(x, y >> 1);
  }

  if (x > y){
    return gcd((x - y) >> 1, y);
  }

  return gcd((y - x) >> 1, x);
}
Esoteric Languages
Esoteric
Interpreters
Algorithms
Logic

This is a way to make Kata in Befunge-98. You can try a Befunge Kata here if you like. I put in an ASCII Mandelbrot set Befunge program in here

let befungeProgramCode=
`&&10p00p00g01p>00g11pv

v                    <
   v\\*a\\<   ;make a large number 30;
>15>1-:#^_$v
v       p03< ;get the r and i values *a large number @ 31 32; ;f(z)=Z^2+C  Z=[Z0*Z0+Z1*Z1+Cr,2*Z0*Z1+Ci];
>10g02p>00g11g-30g*00g/2*30g-2*32p>00g01g-30g*00g/2*30g-2*31p 041p042p 051p >02g1-02p 41g:*30g/42g:*30g/-31g+51p 41g42g2**30g/32g+42p 51g41p v
                                                                            ^         _v#g20      <
                                  ^                            p10-1<           v,,"##"<         vw\\*g034+/g03*:g14/g03*:g24                 <
       ^                                       ,ap11-1_@#:g11p10g00$w0:g10p20g01<          ,,".."<<`;

Jerald is an archaeologist and is trying to decifer a ceaser shift. Create some code to help him out

def decrypt(code,amount):
    #place code here
    let="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    word = ""
    x=0
    for c in range(0,len(code)):
        for i in range (0,len(let)):
            if code[c] == " ":
                word+=" "
                break
            elif code[c] == let[i]:
                x=i
                x-=amount
                if x < 0:
                    x+=26
                word+=let[x]
                break
    return word

Validate string for propper brackets amount and order.
Empty string should return true.

const validate = str => {
  let acc = 0;
  
  for (let i = 0; i < str.length; i += 1) {
    acc = str[i] === '(' ? acc + 1 : acc - 1;
    if (acc < 0) return false;
  }
  
  return acc === 0;
};
object Tail {
  def tail[T](xs: List[T]): List[T] =
    xs.tail
}
function randumString($a){
$a = str_shuffle($a);
return $a;
}

Brainfuck is a Turing-complete language. In other words, you can write any possible program using Brainfuck :) And we will write “Hello, world!”, or rather several;)

Brainfuck consists of only 8 commands:

'>' — move to the next
'<' — move to the previous
'+' — increase the value
'—' — decrease the value
'[' — if the value is zero, go to the next to ']'
']' — if the value is non-zero, go to the next to '['
. (point) — outline the value
, (comma) — enter/save a value

Let's write our first Brainfuck program that will display the text “Hello World!”. The algorithm is simple:

  1. Increase the value in the cell until it is equal to the desired character.
  2. Display the value of symbol in the cell
  3. Go to the next cell.
  4. Repeat until all characters are displayed.
function HelloBrainfuck($text): string {
  $length = strlen($text); $a = "";
  for ($i=0;$i<$length;$i++){
    $curr = ord($text[$i]);
    for ($j=1;$j<=$curr;$j++){
      $a .= "+";
      if ($j == $curr & $i != $length-1){
        $a .= ".>";
      }elseif ($j == $curr){
        $a .= ".";
      }
    } 
  }
  return $a;
}

If we want to instantiate a single object-on-fly we use an anonymous class. Let us discuss a situation, where it could be reasonable to instantiate more than one object from a single anonymous class.

function a(){return new class {};}
$twin1 = a();
$twin2 = a();

You find some interesting messages, but they are encrypted. Find a way to decrypt them!

In those messages, you find some pairs of encrypted - decrypted words.

rwdcoeas - codewars

ndcoig - coding

iaetmahmtc - mathematic

hagtyCrporpy - Cryptography

import math
def decrypt(message):
    # JUST DO IT
    return message