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

This is a solution of creating multiple instance from the same anoynoumous class.

Code
Diff
  • function a(){
      static $poi = null;
      if ($poi) return $poi->create();
      $poi = new class {
         public function create() {
            return new static();
         }
      };
      return $poi->create();
    }
    • function a(){return new class {};}
    • $twin1 = a();
    • $twin2 = a();
    • function a(){
    • static $poi = null;
    • if ($poi) return $poi->create();
    • $poi = new class {
    • public function create() {
    • return new static();
    • }
    • };
    • return $poi->create();
    • }
Bugs

One line version with error output as lambda (analog of arrow function in Python) looks like this.

Code
Diff
  • div = lambda num1, num2 : print("Division failed: division by zero") if num2 == 0 else print("Division failed: integers and floats accepted only") if not(isinstance(num1, (int, float)) and isinstance(num2, (int, float))) else num1 / num2
    
    • let divide = (num1, num2) => num2 === 0 ? console.log("Division failed: division by zero") : !(num1 === +num1 && num2 === +num2) ? console.log("Division failed: integers and floats accepted only") : num1/num2
    • div = lambda num1, num2 : print("Division failed: division by zero") if num2 == 0 else print("Division failed: integers and floats accepted only") if not(isinstance(num1, (int, float)) and isinstance(num2, (int, float))) else num1 / num2
Fundamentals
Arrays
Data Types

The same stuff in one line, using reduce enstead of forEach.

Code
Diff
  • function findOnly(arr) {
      return arr.reduce((acc, cur) => acc ^ cur);
    }
    • function findOnly(arr) {
    • let result;
    • arr.forEach((i) => {
    • result = i ^ result;
    • });
    • return result;
    • return arr.reduce((acc, cur) => acc ^ cur);
    • }
Code
Diff
  • function describePhp() {
      return (
        (2 * 2 == 4) ? 'php is good' : 
        ((2 * 2 == 5) ? 'php is weird' : 'php has features'
      ));
    }
    
    • function describePhp() {
    • return 2 * 2 == 4 ? 'php is good' : 2 * 2 == 5 ? 'php is weird' : 'php has features';
    • return (
    • (2 * 2 == 4) ? 'php is good' :
    • ((2 * 2 == 5) ? 'php is weird' : 'php has features'
    • ));
    • }
Code
Diff
  • import random
    
    def pi_estimate(n, seed=0):
        random.seed(seed)
        
        n_inside = sum(True for i in range(n) if random.random()**2 + random.random()**2 < 1)
        
        return 4 * (n_inside / n)
    • import random
    • def pi_estimate(n, seed=0):
    • random.seed(seed)
    • n_inside = 0
    • for i in range(n):
    • if random.random()**2 + random.random()**2 < 1:
    • n_inside += 1
    • n_inside = sum(True for i in range(n) if random.random()**2 + random.random()**2 < 1)
    • return 4 * (n_inside / n)
Code
Diff
  • class add:
        def __new__(self, x, y):
            return x + y
    • from operator import add as add
    • class add:
    • def __new__(self, x, y):
    • return x + y