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.
Provides fibonacci
function, taken from Dart Pad sample in preload
// Create your own tests here using the Test package (https://github.com/dart-lang/test) // Here is some boilerplate: test('Should be able use the preload fibonacci function', () { expect(fibonacci(20), equals(6765)); }); test('Can randomly call the doubler function as well', () { expect(doubler(fibonacci(20)), equals(13530)); });
- // Create your own tests here using the Test package (https://github.com/dart-lang/test)
- // Here is some boilerplate:
test('Should be able to see stream var', () {expect(nums, new isInstanceOf<Stream>());- test('Should be able use the preload fibonacci function', () {
- expect(fibonacci(20), equals(6765));
- });
test('Should be able to await the streams ints', () async {expect(await nums.toList(), equals([1,2,3,4,5]));});- test('Can randomly call the doubler function as well', () {
- expect(doubler(fibonacci(20)), equals(13530));
- });
#include <type_traits> #include <vector> #define P(f, ...) (printInput(__VA_ARGS__), (f)(__VA_ARGS__)) template <class... Args> void printInput(const Args&... args); Describe(codewarriors) { It(do_print_arguments) { using vi = std::vector<int>; Assert::That(P(hasSize, vi{0, 1, 2}, 3), Is().True()); } }; template <class InputIt> void printContainer(InputIt b, InputIt e) { std::cout << "["; if (b != e) std::cout << *b++; while (b != e) std::cout << ", " << *b++; std::cout << "]"; } template <class T> void printArgs(const std::vector<T>& arg) { printContainer(arg.begin(), arg.end()); } template <class Arg> void printArgs(const Arg& arg) { std::cout << arg; } template <class Arg, class... Args> void printArgs(const Arg& arg, const Args&... args) { printArgs(arg); std::cout << ", "; printArgs(args...); } template <class... Args> void printInput(const Args&... args) { std::cout << "testing with ("; printArgs(args...); std::cout << ")\n"; }
- #include <type_traits>
- #include <vector>
Describe(igloo_framework) {It(does_not_print_arguments) {- #define P(f, ...) (printInput(__VA_ARGS__), (f)(__VA_ARGS__))
- template <class... Args> void printInput(const Args&... args);
- Describe(codewarriors) {
- It(do_print_arguments) {
- using vi = std::vector<int>;
Assert::That(hasSize(vi{0, 1, 2}, 3), Is().True());- Assert::That(P(hasSize, vi{0, 1, 2}, 3), Is().True());
- }
};- };
- template <class InputIt>
- void printContainer(InputIt b, InputIt e) {
- std::cout << "[";
- if (b != e)
- std::cout << *b++;
- while (b != e)
- std::cout << ", " << *b++;
- std::cout << "]";
- }
- template <class T>
- void printArgs(const std::vector<T>& arg) {
- printContainer(arg.begin(), arg.end());
- }
- template <class Arg>
- void printArgs(const Arg& arg) {
- std::cout << arg;
- }
- template <class Arg, class... Args>
- void printArgs(const Arg& arg, const Args&... args) {
- printArgs(arg);
- std::cout << ", ";
- printArgs(args...);
- }
- template <class... Args>
- void printInput(const Args&... args) {
- std::cout << "testing with (";
- printArgs(args...);
- std::cout << ")\n";
- }
Random numbers in PHP
Not sure if I'm doing this right but anyway here's my take at random numbers in PHP.
lcg_value
Accepts no arguments and returns a random float between 0 (inclusive) and 1 (exclusive).
rand
Optionally accepts 2 arguments. If no arguments provided, returns a random integer from 0 to get_rand_max()
. If both arguments provided, returns random integer between the stated minimum and maximum (both inclusive).
echo "<DESCRIBE::>Random Numbers in PHP\n"; echo "<IT::>Demonstrating lcg_value()\n"; for ($i = 0; $i < 100; $i++) { echo "<PASSED::>" . lcg_value() . "\n"; } echo "<COMPLETEDIN::>\n"; echo "<IT::>Demonstrating rand() with no arguments\n"; for ($i = 0; $i < 100; $i++) { echo "<PASSED::>" . rand() . "\n"; } echo "<COMPLETEDIN::>\n"; echo '<IT::>Demonstrating rand($min, $max) with $min = 0 and $max = 100 (like how the random_number/randomNumber method generates random integers in most Codewars testing frameworks)' . "\n"; for ($i = 0; $i < 100; $i++) { echo "<PASSED::>" . rand(0, 100) . "\n"; } echo "<COMPLETEDIN::>"; echo "<COMPLETEDIN::>";
#include <algorithm>#include <iterator>#include <random>#include <vector>void run() {using namespace std;// this is a source of true random numbersrandom_device rd;// it's used to generate a seed for an enginedefault_random_engine eng(rd());// distribution is applied to a generator to generate random numbersuniform_int_distribution<int> dist(1, 10);vector<int> xs;for (unsigned i = 0; i < 20; i++)xs.push_back(dist(eng));for (int x : xs)cout << x << ' ';cout << '\n';- echo "<DESCRIBE::>Random Numbers in PHP\n";
- echo "<IT::>Demonstrating lcg_value()\n";
- for ($i = 0; $i < 100; $i++) {
- echo "<PASSED::>" . lcg_value() . "\n";
- }
void run2() {using namespace std;default_random_engine eng{random_device()()};uniform_int_distribution<int> dist(1, 10);auto rand10 = [&eng, &dist]() { return dist(eng); };vector<int> xs;generate_n(back_inserter(xs), 20, rand10);copy(cbegin(xs), cend(xs), ostream_iterator<int>(cout, " "));cout << '\n';- echo "<COMPLETEDIN::>\n";
- echo "<IT::>Demonstrating rand() with no arguments\n";
- for ($i = 0; $i < 100; $i++) {
- echo "<PASSED::>" . rand() . "\n";
- }
- echo "<COMPLETEDIN::>\n";
- echo '<IT::>Demonstrating rand($min, $max) with $min = 0 and $max = 100 (like how the random_number/randomNumber method generates random integers in most Codewars testing frameworks)' . "\n";
- for ($i = 0; $i < 100; $i++) {
- echo "<PASSED::>" . rand(0, 100) . "\n";
- }
- echo "<COMPLETEDIN::>";
- echo "<COMPLETEDIN::>";
(ns power.core) (defn power [n e] (condp = e 0 1 (* n (power n (dec e)))))
function power_of(int $x, int $y) {return $x ** $y;}- (ns power.core)
$test->describe("Basic Power Function", function () {global $test;$test->it("should always return when the power is 0", function () {global $test;$test->assert_equals(power_of(1, 0), 1);$test->assert_equals(power_of(2, 0), 1);$test->assert_equals(power_of(6, 0), 1);$test->assert_equals(power_of(100, 0), 1);$test->assert_equals(power_of(1000, 0), 1);$test->assert_equals(power_of(99999, 0), 1);$test->assert_equals(power_of(666, 0), 1);$test->assert_equals(power_of(33, 0), 1);$test->assert_equals(power_of(123456789, 0), 1);$test->assert_equals(power_of(911, 0), 1);});$test->it("should work for other powers", function () {global $test;$test->assert_equals(power_of(1, 1), 1);$test->assert_equals(power_of(4, 2), 16);$test->assert_equals(power_of(2, 4), 16);$test->assert_equals(power_of(5, 3), 125);$test->assert_equals(power_of(2, 9), 512);$test->assert_equals(power_of(7, 3), 343);$test->assert_equals(power_of(6, 3), 216);$test->assert_equals(power_of(3, 6), 729);$test->assert_equals(power_of(9, 3), 729);$test->assert_equals(power_of(10, 10), 10000000000);$test->assert_equals(power_of(2, 53), 9007199254740992);});});- (defn power [n e]
- (condp = e
- 0 1
- (* n (power n (dec e)))))
;; TODO: TDD development using clojure.test framework
- ;; TODO: TDD development using clojure.test framework
Taking a look at Igloo testing framework.
I think there must be some automatical header generation going on here...
Now we get error: 'auto' not allowed in function prototype
. Gcc compiles this, clang doesn't. It's not standard C++ yet, but maybe C++17.
function greet_language($lang = "PHP") { print "Hello $lang!\n"; } greet_language(); greet_language("Javascript"); greet_language("Ruby");
(ns hello.core)(println "Hello Clojure")- function greet_language($lang = "PHP") {
- print "Hello $lang!\n";
- }
- greet_language();
- greet_language("Javascript");
- greet_language("Ruby");
#include <string> #include <stdio.h> int Main() { int arg1, arg2, add, sub, mul, quo, rem ; printf( "Enter two integer numbers : " ); scanf( "%d%d", &arg1, &arg2 ); //no scanf provided hope to get memory garbage as number /* Perform Addition, Subtraction, Multiplication & Division */ __asm__ ( "addl %%ebx, %%eax;" : "=a" (add) : "a" (arg1) , "b" (arg2) ); __asm__ ( "subl %%ebx, %%eax;" : "=a" (sub) : "a" (arg1) , "b" (arg2) ); __asm__ ( "imull %%ebx, %%eax;" : "=a" (mul) : "a" (arg1) , "b" (arg2) ); __asm__ ( "movl $0x0, %%edx;" "movl %2, %%eax;" "movl %3, %%ebx;" "idivl %%ebx;" : "=a" (quo), "=d" (rem) : "g" (arg1), "g" (arg2) ); printf( "%d + %d = %d\n", arg1, arg2, add ); printf( "%d - %d = %d\n", arg1, arg2, sub ); printf( "%d * %d = %d\n", arg1, arg2, mul ); printf( "%d / %d = %d\n", arg1, arg2, quo ); printf( "%d %% %d = %d\n", arg1, arg2, rem ); return 0 ; }
int main(){printf("%d\n", test());}- #include <string>
- #include <stdio.h>
int test()- int Main()
- {
__asm__("movl $1337, %eax");- int arg1, arg2, add, sub, mul, quo, rem ;
- printf( "Enter two integer numbers : " );
- scanf( "%d%d", &arg1, &arg2 ); //no scanf provided hope to get memory garbage as number
- /* Perform Addition, Subtraction, Multiplication & Division */
- __asm__ ( "addl %%ebx, %%eax;" : "=a" (add) : "a" (arg1) , "b" (arg2) );
- __asm__ ( "subl %%ebx, %%eax;" : "=a" (sub) : "a" (arg1) , "b" (arg2) );
- __asm__ ( "imull %%ebx, %%eax;" : "=a" (mul) : "a" (arg1) , "b" (arg2) );
- __asm__ ( "movl $0x0, %%edx;"
- "movl %2, %%eax;"
- "movl %3, %%ebx;"
- "idivl %%ebx;" : "=a" (quo), "=d" (rem) : "g" (arg1), "g" (arg2) );
- printf( "%d + %d = %d\n", arg1, arg2, add );
- printf( "%d - %d = %d\n", arg1, arg2, sub );
- printf( "%d * %d = %d\n", arg1, arg2, mul );
- printf( "%d / %d = %d\n", arg1, arg2, quo );
- printf( "%d %% %d = %d\n", arg1, arg2, rem );
- return 0 ;
- }
// TODO: TDD development by writing your own tests as you solve the kata Describe(any_group_name_you_want) { It(should_do_something) { Assert::That(Main(), Equals(0)); } };
- // TODO: TDD development by writing your own tests as you solve the kata
- Describe(any_group_name_you_want)
- {
- It(should_do_something)
- {
- Assert::That(Main(), Equals(0));
- }
- };