Start a new Kumite
AllAgda (Beta)BF (Beta)CCFML (Beta)ClojureCOBOL (Beta)CoffeeScriptCommonLisp (Beta)CoqC++CrystalC#D (Beta)DartElixirElm (Beta)Erlang (Beta)Factor (Beta)Forth (Beta)Fortran (Beta)F#GoGroovyHaskellHaxe (Beta)Idris (Beta)JavaJavaScriptJulia (Beta)Kotlinλ Calculus (Beta)LeanLuaNASMNim (Beta)Objective-C (Beta)OCaml (Beta)Pascal (Beta)Perl (Beta)PHPPowerShell (Beta)Prolog (Beta)PureScript (Beta)PythonR (Beta)RacketRaku (Beta)Reason (Beta)RISC-V (Beta)RubyRustScalaShellSolidity (Beta)SQLSwiftTypeScriptVB (Beta)
Show only mine

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.

### Cap function

example: `cap(0, 10, 11) => 10`

11 is greater than 10, therefore it caps to 10

example: `cap(5, 10, 1) => 5`

1 is less than 5, therefore it caps to 5

example: `cap(0, 10, 5) => 5`

5 is within 0 < x < 10, therefore it returns the number

``````def cap(low, high, num):
if num < low: return low
elif num > high: return high
else: return num``````

### Count long Trailing Zeros

Binary

Take an `n` long as argument and return a `int` type representing the number of trailing zero's of `n` bits

``````public class CtzKumite
{
public static int CountTrailingZero(long num)
{
if (num == 0) return 32;

uint res = 0;
num &= (uint)-(int)num;
var tmp = num >> 16; if (tmp != 0) { num = tmp; res += 16; }
tmp = num >> 8; if (tmp != 0) { num = tmp; res += 8; }
tmp = num >> 4; if (tmp != 0) { num = tmp; res += 4; }
return (int)(res + ((num >> 1) - (num >> 3)));
}
}``````

### Everest_Climber1's Kumite #6

``float AverageDisplacement(float u, float v, float t) { return ((u + v) / 2) * t; }``

### String to Base64

Base64 is a url encoding scheme that many websites use in their urls as sometimes some characters are not allowed or can become malformed in a url. So Base64 turns any text into allowed ascii characters that will not become malformed in a url.

Your job is to create a program that takes in a String and returns the equivalent Base64 String without using any imports or built in functions.

The base64 encoding scheme goes as follows: You first take in your String, and convert every character into the 8bit binary reprentation of each ascii value ie (a is 97, 97 is 01100001). You you then make sure that the entirety of your string is a multiple of 6 (as Base64 works with 6 bits at a time) you then get the ascii value of each 6 bit chunk and you return that.

Sounds easy enough, right? However here are some things to remember, any characters you add to make sure that your binary String is a multiple are 6 are called, "Padding" in Base64 you represent the padding as, "=" and the end of your string.

https://www.base64decode.org // a website that correctly implements base64 to check your work

Here are some examples:

"This is Base64" >> "VGhpcyBpcyBCYXNlNjQ="

"Test" >> "VGVzdAo="

"Purple" >> "UHVycGxl"

Good luck!!

``````public class Convert {
public static void main(String[] args) {

}

public static String toBinary(int n) {
String returnValue = "";
char[] encodingTable = "01".toCharArray();
while (n > 0) {
returnValue = encodingTable[n % 2] + returnValue;
n /= 2;
}
while (returnValue.length() < 8) {
returnValue = "0" + returnValue;
}
return returnValue;
}

public static int fromBinary(String n) {
int result = 0;
int pos = n.length()-1;
for(int i = 0; i < n.length(); i++) {
if (n.substring(i, i + 1).equals("1")) {
result += Math.pow(1 * 2,pos);
}
pos--;
}
return result;
}

public static String toBase64(String str) {
String strAsBinary = "";
String returnValue = "";
char[] encodingTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();

for(int i = 0; i < str.length(); i++) {
strAsBinary += toBinary((int) (str.substring(i, i + 1).charAt(0)));
}
while (strAsBinary.length() % 6 != 0) {strAsBinary = strAsBinary + "0";}
for(int i = 0; i < strAsBinary.length(); i += 6) {
returnValue += encodingTable[fromBinary(strAsBinary.substring(i, i + 6))];
}
for(int i = 0; i < padding; i++) {returnValue = returnValue + "=";}
return returnValue;

}

}``````
Failed Tests

### Mastermind

``````class Mastermind{
static String evaluate(String secret, String guess) {
return "";
}
}``````
Failed Tests

### Lambda weirdness showcase

``````% Try enabling and disabling this import, compare the differences
:- use_module(library(clpfd)).

% explicitely include N. Always works
foo(Xs, N, Rs) :-
maplist({N}/[L,R] >> (R is L * N), Xs, Rs).

% do not include N, throws an error dependant on the import
bar(Xs, N, Rs) :-
maplist([L,R] >> (R is L * N), Xs, Rs).``````

# Quipu

Quipu is an ancient recording device from Andean South America. It was likely used as an accounting record.

Quipu article in Wikipedia

We chose to represent each knot as a number, and the positions as the position in an array, being the rightmost item the furthest knot in the rope.

It also had an error prevention method, being the first number the sum of the rest.

Return the number if the sum checks out, if not return -1.

``````import java.util.ArrayList;
public class Quipu {

public static int calculate(ArrayList<int[]> strings){
if (strings==null||strings.isEmpty())return -1;
int primero=0;
int suma=0;
for (int i = 0; i < strings.size(); i++) {
StringBuilder sb1 = new StringBuilder();
for (int num : strings.get(i)) {
sb1.append(num);
}
if (i == 0) {
primero=Integer.parseInt(sb1.toString());
}else{
suma+=Integer.parseInt(sb1.toString());
}
}
if(primero==suma)
return primero;
else return -1;
}
}``````
Failed Tests

### Will the delivery man arrive on time?

Arrays
Fundamentals

A delivery man has to deliver a package in 15 minutes,the address is in the coordinates [4][5], but his gps is not working right, will he arrive at time?.
Every move takes a minute.
Moves can be NORTH,SOUTH,EST,WEST.
Representing directions ['n','s','e','w'] (No case sensitive).
Also you can find a traffic jam, is represented by '/' and consumes 2 minutes.

Your task is to create a function that return true if he arrives on time, else return false.

Note: you will always receive a valid array containing a random assortment of direction letters ('n', 's', 'e', 'w' or '' only). It will never give you an empty array (return false).

``````public class ArriveAtTime{

public static boolean arriveAtTime(char [] movements){

}
}``````

### Banking Statement

Your bank is tired of its mainframe COBOL accounting software and they hired both of you for a greenfield project in - what a happy coincidence

Requirements
Write a class Account that offers the following methods void deposit(int) void withdraw(int) String printStatement()

An example statement would be:

Date Amount Balance
24.12.2015 +500 500
23.8.2016 -100 400

``````class Account {
void deposit(int amount){

}

String getStatement() {
return "100";
}

}``````
Failed Tests

### mystery men's Kumite #2

``````File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 68, in __exec_python_cmd
txt = exec_python(*cmd, env=pp_env)
File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\compat.py", line 526, in exec_python
return exec_command(*cmdargs, **kwargs)
File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\compat.py", line 321, in exec_command
out = out.decode(encoding)
AttributeError: 'str' object has no attribute 'decode'
1234567``````