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

Nigelius is a new Hero in Mobile Legends, and you are invited for an interview by Shanghai Moonton
Technology for a game developer position. Nigelius the Bloodborn has a passive skill that increases
his damage for every 250 HP he has, and your task is to code this skill. The increase goes as
follows:

at  250 HP    +1 damage
at  500 HP    +4 damage
at  750 HP    +9 damage
at 1000 HP    +16 damage
at 1250 HP    +25 damage
.
.
.
at 2000 HP    +64 damage
at 2250 HP    +81 damage
...etc

That is, we determine how many chunks of 250 HP Nigelius has, and then we square it to get the bonus
damage. Write a function getBonusDamage given the current health of Nigelius.

Nigelius does not get fractional damage bonuses, in other words, 500 and 600 HP will give him +4
bonus damage. 749 HP will also give him +4 bonus damage.

function getBonusDamage(currentHP) {
return Math.trunc(currentHP / 250) ** 2
}

### 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

### JavaScript Foundations: Variables: Values of Data in Everyday Life

Okay.

Code
Diff
• const yearlyElectricCosts = () => {
// Create 11 more variables with the correct values
let januaryBill = 43.11
let februaryBill = 50.21
let marchBill = 48.92
let aprilBill = 62.36
let mayBill = 54.64
let juneBill = 49.30
let julyBill = 61.93
let augustBill = 68.54
let septemberBill = 71.77
let octoberBill = 70.28
let novemberBill = 59.56
let decemberBill = 62.04

// Decide on a variable name and add all the monthly charges
const totalCharges = januaryBill + februaryBill + marchBill + aprilBill + mayBill + juneBill + julyBill + augustBill + septemberBill + octoberBill + novemberBill + decemberBill

// Return the value of the variable by typing it in after the `return` keyword below
return +totalCharges.toFixed(2)
}
•  1 1 const yearlyElectricCosts = () => { 2 2 // Create 11 more variables with the correct values 3 3 let januaryBill = 43.11 4 − 4 + let februaryBill = 50.21 5 + let marchBill = 48.92 6 + let aprilBill = 62.36 7 + let mayBill = 54.64 8 + let juneBill = 49.30 9 + let julyBill = 61.93 10 + let augustBill = 68.54 11 + let septemberBill = 71.77 12 + let octoberBill = 70.28 13 + let novemberBill = 59.56 14 + let decemberBill = 62.04 15 + 5 5 // Decide on a variable name and add all the monthly charges 6 − const 17 + const totalCharges = januaryBill + februaryBill + marchBill + aprilBill + mayBill + juneBill + julyBill + augustBill + septemberBill + octoberBill + novemberBill + decemberBill 7 7 8 8 // Return the value of the variable by typing it in after the `return` keyword below 9 − return 20 + return +totalCharges.toFixed(2) 10 10 }