Search
• ###### Filter by Language:
• 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.

### Nigelius

Control Flow
Basic Language Features
Fundamentals

Code
Diff
• ``: getBonusDamage ( health -- bonus ) 250 / dup * ;``
•  1 − ```function getBonusDamage(currentHP) { ``` 2 − ``` return Math.trunc(currentHP / 250) ** 2 ``` 3 − ```} ``` 1 + ```: getBonusDamage ( health -- bonus ) 250 / dup * ; ```

Recent Moves:

### GCD for any set of numbers

Arithmetic
Mathematics
Algorithms
Numbers
Code
Diff
• ``````from math import gcd

def greatest_common_divisor(*args):
# iterates through entirety of args every time
return __import__("functools").reduce(gcd, args)

def greatest_common_divisor(*args):
acc = args[0]
for i in range(1, len(args)):
if acc == 1:
return 1
acc = gcd(acc, args[i])
return acc
``````
•  1 − ```def greatest_common_divisor(*args): ``` 1 + ```from math import gcd ``` 2 2 3 − ``` def gcd(a, b): ``` 4 − ``` if a == b: return a ``` 5 − ``` elif a > b: ``` 6 − ``` return (gcd(b, a % b) if a % b != 0 else b) ``` 7 − ``` else: ``` 8 − ``` return gcd(b, a) ``` 3 + ```def greatest_common_divisor(*args): ``` 4 + ``` # iterates through entirety of args every time ``` 5 + ``` return __import__("functools").reduce(gcd, args) ``` 9 9 10 − ``` res = gcd(args[0], args[1]) ``` 11 − ``` if len(args) > 2: ``` 12 − ``` for i in range(2, len(args)): ``` 13 − ``` res = gcd(res, args[i]) ``` 14 − ``` return res ``` 7 + ```def greatest_common_divisor(*args): ``` 8 + ``` acc = args[0] ``` 9 + ``` for i in range(1, len(args)): ``` 10 + ``` if acc == 1: ``` 11 + ``` return 1 ``` 12 + ``` acc = gcd(acc, args[i]) ``` 13 + ``` return acc ```

### test

Code
Diff
• ``kata=lambda x:x[:1]=="a"``
•  1 − ```kata=lambda x:x[0]=='a' ``` 1 + ```kata=lambda x:x[:1]=="a" ```

### C++ : Iterating over two vectors at the same time till end of one

Code
Diff
• ``````#include <vector>
#include <iostream>

template <class T, class U>
void iterateTwoVectors(std::vector<T> A, std::vector<U> B)
{
for (struct {typename std::vector<T>::const_iterator a; typename std::vector<U>::const_iterator b;} s = {A.begin(), B.begin()}; s.a < A.end() && s.b < B.end(); ++s.a, ++s.b)
std::cout << *s.a << ":" << *s.b << "\n";
}``````
•  1 1 ```#include ``` 2 − ```#include ``` 3 3 ```#include ``` 3 + 4 4 ```template ``` 5 5 ```void iterateTwoVectors(std::vector A, std::vector B) ``` 6 6 ```{ ``` 7 − 8 − ``` for (auto [a,b] = std::tuple{A.begin(), B.begin()}; a != A.end() && b != B.end(); a++, b++) ``` 9 − ``` { ``` 10 − ``` std::cout << *a << ":" << *b << "\n"; ``` 11 − ``` } ``` 7 + ``` for (struct {typename std::vector::const_iterator a; typename std::vector::const_iterator b;} s = {A.begin(), B.begin()}; s.a < A.end() && s.b < B.end(); ++s.a, ++s.b) ``` 8 + ``` std::cout << *s.a << ":" << *s.b << "\n"; ``` 12 12 ```} ```

### Fibonacci ( JS )

`fib` is `O(n²)` in practice, probably because of BigInt arithmetic.

There is also an optimisation calculating `fib(n)` in terms of `fib(approx half n)`, which is actually logarithmic before BigInt arithmetic. That's even faster, in this case.

Code
Diff
• ``````function fib(n) {
for ( let [a,b]=[0n,1n], i=0;; i++ )
if ( i<n )
[a,b] = [b,a+b];
else
return a;
}``````
•  1 − ```module Example where ``` 2 − 3 − ```import Data.Semigroup (Endo(..),stimes) ``` 4 − 5 − ```fib :: Integer -> Integer ``` 6 − ```fib = fst . (`appEndo` (0,1)) . (`stimes` Endo ( \ (a,b) -> (b,a+b) )) ``` 1 + ```function fib(n) { ``` 2 + ``` for ( let [a,b]=[0n,1n], i=0;; i++ ) ``` 3 + ``` if ( i

Recent Moves:

### and, or and xor without "&&" and "||"

Code
Diff
• ``````bool Or(bool a,bool b){return(~-((~-(a)*~-(b)))*~-((~-(a)*~-(b))));}bool And
(bool a,bool b){return(~-((~-(a)*~-(a)))*~-((~-(b)*~-(b))));}bool Xor(bool a
,bool b){return(~-((~-((~-((~-((~-(a)*~-(a)))*~-((~-(b)*~-(b)))))*~-((~-(a)*
~-(b)))))*~-((~-((~-((~-(a)*~-(a)))*~-((~-(b)*~-(b)))))*~-((~-(a)*~-(b))))))
)*~-((~-((~-((~-((~-(a)*~-(a)))*~-((~-(b)*~-(b)))))*~-((~-(a)*~-(b)))))*~-((
~-((~-((~-(a)*~-(a)))*~-((~-(b)*~-(b)))))*~-((~-(a)*~-(b))))))));}``````
•  1 − ```bool Or ( bool a, bool b ){ return a ? a : b; } ``` 2 − ```bool And ( bool a, bool b ){ return a ? b : false; } ``` 3 − ```bool Xor ( bool a, bool b ){ return And(a,b) ? false: Or(a,b); } ``` 1 + ```bool Or(bool a,bool b){return(~-((~-(a)*~-(b)))*~-((~-(a)*~-(b))));}bool And ``` 2 + ```(bool a,bool b){return(~-((~-(a)*~-(a)))*~-((~-(b)*~-(b))));}bool Xor(bool a ``` 3 + ```,bool b){return(~-((~-((~-((~-((~-(a)*~-(a)))*~-((~-(b)*~-(b)))))*~-((~-(a)* ``` 4 + ```~-(b)))))*~-((~-((~-((~-(a)*~-(a)))*~-((~-(b)*~-(b)))))*~-((~-(a)*~-(b)))))) ``` 5 + ```)*~-((~-((~-((~-((~-(a)*~-(a)))*~-((~-(b)*~-(b)))))*~-((~-(a)*~-(b)))))*~-(( ``` 6 + ```~-((~-((~-(a)*~-(a)))*~-((~-(b)*~-(b)))))*~-((~-(a)*~-(b))))))));} ```

### Add the missing Product function

Found the product function in 2.6.

Code
Diff
• ``````from itertools import product

def prod(numbers):
return len([*product(*map(range, numbers))]) if numbers else 0``````
•  1 + ```from itertools import product ``` 2 + 1 1 ```def prod(numbers): ``` 2 − ``` if numbers == []: return 0 ``` 3 − ``` product = 1 ``` 4 − ``` for number in numbers: ``` 5 − ``` product *= number ``` 6 − ``` return product ``` 4 + ``` return len([*product(*map(range, numbers))]) if numbers else 0 ```