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.
This is a solution
of creating multiple instance from the same anoynoumous class.
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();
- }
// PHPUnit Test Examples: // TODO: Replace examples and use TDD development by writing your own tests class MyTestCases extends TestCase { // test function names should start with "test" public function testThatSomethingShouldHappen() { $this->assertSame(get_class(a()), get_class(a())); } }
- // PHPUnit Test Examples:
- // TODO: Replace examples and use TDD development by writing your own tests
- class MyTestCases extends TestCase
- {
- // test function names should start with "test"
- public function testThatSomethingShouldHappen() {
- $this->assertSame(get_class(a()), get_class(a()));
- }
- }
One line version with error output as lambda (analog of arrow function in Python) looks like this.
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
The same stuff in one line, using reduce
enstead of forEach
.
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'
- ));
- }
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 = 0for 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)