Begin a new Kumite
  • 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.

Invert a color from a hex code

Create a function invert which takes a string (a valid 6-digit hex code color without the hashtag, e.g. "2F4A69") and returns the exact color inverse of the original hex (as a string).
Look at "Test Cases" or "Sample Tests" if this is a little confusing.
Assume all inputs are valid. Good fun, have luck.

function invert(hex) {
  let int = parseInt(hex, 16);
  int = 0xFFFFFF ^ int;
  return int.toString(16).padStart(6, '0').toUpperCase();
def addNumbers(a, b):
    return a+b
Control Flow
Basic Language Features

Return early from a function with some data if condition is met withing child function, otherwise return 'no return'.

The test inputs 'toReturn' and 'returnWhat' MUST be passed to child funciton and SHOULD NOT be referenced in parent. No mutations of test inputs should occur.

const returnFromChild=(toReturn, returnWhat)=>{
  const child=(toRet, retWhat)=>{
      return retWhat
  const retThis = child(toReturn,returnWhat);
    return retThis
  return 'no return'

In the game of dota2 you can either play in two modes: solo (alone) or in a party (with a group of 2+ players). The outcome of these games is either a win or a loss. You gain or lose MMR (matchmaking rating) accordingly.

If you win a dota2 game while in a party, you gain 20 MMR. You lose 20 MMR if you lose the game.

However, if you win a dota2 game while playing solo then you gain 30 MMR and you lose 30 MMR if you lose.

This is because winning with your friends is considered more difficult.

Write a method that will determine the mmr you would get based on the outcome of the game and the type of mode you are playing.

def mmr(party: bool, win: bool) -> int:
    if party and win:
        return 20
    elif party and not win:
        return -20
    elif not party and win:
        return 30
        return -30

Without Linq.
If there is more than one equal value, return any

using System;

public class Kata
  public static int MinIndex(int[] array)
     int minIndex = 0;
     for (int j = 0; j < array.Length; j++)
        if (array[j] < array[minIndex])
                    minIndex = j;
     return array[minIndex];

You are given distance values between point A and B in the form of Kilometers(km).
Find the largest Distance, convert to miles and return.

miles = km/1.609344

(4.828032,8.04672, 16.09344) > 10

def numbers(n):

This kumite determines if a string only has closed parentheses. The goal is to optimize the runtime of the program. Currently, it runs in about 2.8 seconds through the test suite. Can it be better?

bool isBalanced(const std::string& s) {
  int count = 0;
  for (size_t i = 0; i < s.length(); i++) {
    if (s[i] == '(') {
    if (s[i] == ')') {
      if (count <= 0) { return false; }
  return true;

Find the difference and explain why it is so significant.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ForCodeWars
    class Program
        static void Main(string[] args)
            const int length = 10000;

            int[,] arrayA = new int[length, length];

            Stopwatch timer = new Stopwatch();

            for (int i = 0; i < length; i++)
                for (int j = 0; j < length; j++)
                    arrayA[i, j] = i;


            Stopwatch timer2 = new Stopwatch();

            int[,] arrayB = new int[length, length];
            for (int i = 0; i < length; i++)
                for (int j = 0; j < length; j++)
                    arrayB[j, i] = i;




The point of this function is to handle situations where a value is compared against a series of consistently decreasing or increasing values, in a branchless way.

For example - Let's assume you had a bunch of grades and you wanted to return the letter representation of those grades. The most generic solution would be to write a stream of conditional statements, each returning the appropriate grade letter. That certainly would work, but it would not be branchless.

Instead, every condition is checked, and the sum of initial consecutive True conditions is used as the index for an iterable of choices to return from. The trickiest part of this is making sure that once aFalse condition is encountered no remaining conditions will be recognized as True. To make it even more dynamic it should also be possible to determine if each condition is not True.

Note that AND NOT is not the same thing as NAND. It may be functionally the same (maybe), but it is not logically the same. This is evidenced by sum. sum is adding all the True statements together which is base 10 AND logic.

Essentially, using the functions "NOT" (_) argument will result in this logic:

value AND (NOT next value) AND (NOT next value)...

returns a value from a list/tuple indexed by the sum of initial consecutive True conditions
    val    : the comparator
    op     : operator to use
    comp   : list/tuple of contrasts or comparisons = (`if`,`and`,`and`,...)
    choices: list/tuple of choices to return from   = (`else`,`if`,`and`,`and`,...)
    _      : reverse condition value (not)
def br_and(val, op, comp, choices, _=0):
    return (l:=1, choices[sum(l:=l*(op(val, cval)^_) for cval in comp)])[-1]


Improve it, this is primitive.
Add pyfiglet, improve the saving mechanism to avoid typing the swap fee each time you boot the program.

Also, why restart the program everytime? let's return to the beginning if we typed the choice variable wrong.


A tool i've made for a popular trading app, I have deleted the name of the app and changed it to generic "trading"

IMPORTANT CONTEXT: swap fee should be a number like 0.05869 or 0.12569. It is never more than one full dollar.

# a tool i've made for a popular trading app, deleted the name of the app and changed it to generic "trading"

# IMPORTANT CONTEXT swap fee should be a number like 0.05869 or 0.12569 , you get the idea

print ("""  
Trading Swap Fees  
   ____      _            _       _               
  / ___|__ _| | ___ _   _| | __ _| |_ ___  _ __   
 | |   / _` | |/ __| | | | |/ _` | __/ _ \| '__|  
 | |__| (_| | | (__| |_| | | (_| | || (_) | |     

print ('Welcome to the Trading Swap Fee calculator. These are your saved instruments: \n')
with open('swaplist.txt') as f:
		lines = f.readlines()
		print (lines)

choice = input('Choose your action: 1.Calculate or 2.Save a new instrument \n')

if choice == '1':
	quantity = int(raw_input('Enter QUANTITY of instrument held. (enter an integer) \n')) 
	swap_rate = float(raw_input('Enter SWAP RATE of instrument. (enter a decimal) \n'))
	nights = int(raw_input('Enter how many nights will you hold \n'))

	result = quantity * swap_rate * nights
	print ('This is the swap fee you will pay: \n')
	print (result)

elif choice == '2':

	if os.path.isfile("swaplist.txt"):
	#import list
		list_of_stocks = open('swaplist.txt','r').read().split('/n')
		list_of_stocks = []

#ask for new users
	new_stock = raw_input('Save a position in this format: NAME, SHORT FEE, LONG FEE \n')


	with open('swaplist.txt','w') as f:

	with open('swaplist.txt') as f:
		lines = f.readlines()

	print('Saved. Please restart the program')


	print('Wrong choice. Please restart the program')