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.

### Linear search

Linear search with while loop:

• Every Iteration
1. check if i is smaller than length of array, if not increament i
2. check if arr[i] equals to x
• Do
• Once
1. check if last item is equal to x, if yes return index
2. if not, replace last array item with x, saving the last item in another variable
3. if i is smaller than length of array, return i
4. else return nil
- Every Iteration
5. check if arr[i] equals to x, if not increament i
``````def Linear_search(arr,x)
i=0
last_idx=arr.size-1
if arr[last_idx] == x
return last_idx
else
last = arr[last_idx]
arr[last_idx]=x
end
while arr[i]!=x
i+=1
end
i < last_idx ? i : nil
end``````

### Flip Flop

``````flop,(<%>) :: (Functor f) -> f (a -> b) -> a -> f b
``````

Specialises to `flip` for `(->) r`;
otherwise useful for `take <\$> choose (0,length xs) <%> xs`and similar binary function constructs with functors / applicatives / monads.

Known elsewhere as `Control.Lens.(??)` and `Relude.Functor.Fmap.flap`

``````module FlipFlop (flop,(<%>)) where

infixl 4 `flop`,<%>

flop,(<%>) :: (Functor f) => f (a -> b) -> a -> f b
flop fab a = fmap (\$ a) fab
(<%>) = flop

{-# Specialise  flop :: (a -> b -> c) -> b -> a -> c #-}
{-# Specialise (<%>) :: (a -> b -> c) -> b -> a -> c #-}``````

### Palindrome

Arrays
Data Types
Control Flow
Basic Language Features
Fundamentals

Palindrome:

A palindrome is a word that when reversed reads the same. An example is "evil rats star live."

Valid palindromes should output 'TRUE' while invalid ones should output 'FALSE'.

``````function palindrome (x) {
let s = x.split('').reverse().join('')
return x == s ? "TRUE" : "FALSE"
}``````

### Interleave lists

Fundamentals

You are asking to write a function, which takes N lists as input, such so len(l1) >= len(l2) >= .. len(lN) and interleave them into a single list. If you get a single list in input, then just return original list as is.

Example:
You have ['a1','a1','a3'], ['b1','b2'],['c1'] to interleave. Finually, you should get ['a1','b1','c1','a2','b2','c1'].

``````def interleave(*argv):
lists = len(argv)
if 1 == lists:
return argv[0]
else:
o = [x for t in zip(*argv) for x in t]
for i in reversed(range(0, lists - 1)):
l = len(argv[i + 1])
lists = []
for _list in argv[:i+1]:
lists.append(_list[l:])
o += [x for t in zip(*lists) for x in t]
return o``````

### Maurer Rose

Just seeing if I can get the canvas element to work.

The best way to see the canvasses is to hit Fork, then Run, then look at the test logs.

https://en.wikipedia.org/wiki/Maurer_rose

``````function maurerRose(n, d, length) {
length /= 2
var locations = []
for (var i = 0; i <= 360; i++) {
var k = i * d * Math.PI / 180
var r = Math.sin(n * k) * length
var a = r * Math.cos(k) + length
var b = r * Math.sin(k) + length
locations.push([Math.round(a), Math.round(b)])
}
return locations
}``````

### Unique in order - slow execution

I have tried the Kata below, but the execution is too slow, what can I do to make this script faster?

"Implement the function unique_in_order which takes as argument a sequence and returns a list of items without any elements with the same value next to each other and preserving the original order of elements.

For example:

unique_in_order('AAAABBBCCDAABBB') == ['A', 'B', 'C', 'D', 'A', 'B']

unique_in_order('ABBCcAD') == ['A', 'B', 'C', 'c', 'A', 'D']

unique_in_order([1,2,2,3,3]) == [1,2,3]

``````def unique_in_order(iterable):
iterable = list(iterable)
while 1==1:
for x in range(len(iterable)):
if iterable[x]==iterable[x-1]:
del iterable[x]
break
if x==len(iterable)-1:
return iterable``````

### Merge two sorted arrays from scratch

You are given two arrays of integers, sorted in ascending order. Your task is to write a function that merges the two arrays, and output a merged array that is also sorted. But there's the catch! The `Array.prototype.sort()` function is not available!

For example, given the following two arrays:

``````[0, 3, 6, 13, 45]
[-1, 45, 330, 553]
``````

Your function should return:

``````[-1, 0, 3, 6, 13, 45, 45, 330, 553]
``````

Note that there may be duplicates. It's fine to leave them in there.

``````function mergeArrays(arrA, arrB) {
const output = [];
const arrAClone = [...arrA];
const arrBClone = [...arrB];
let nextSmallestA = arrAClone.shift();
let nextSmallestB = arrBClone.shift();
while (nextSmallestA !== undefined || nextSmallestB !== undefined) {
if (nextSmallestA === undefined || nextSmallestB < nextSmallestA) {
output.push(nextSmallestB);
nextSmallestB = arrBClone.shift();
} else {
output.push(nextSmallestA);
nextSmallestA = arrAClone.shift();
}
}
return output;
}``````

### Birthday Guessing

``````import java.util.*;
public class Main {

public static void main(String[] args) {
int finalResult, month, date, year, flag = 0;
String alphabeticalRepresentationOfMonth, suffix;
System.out.println("Lets play a game");
System.out.println("I'll guess your Birthday!");
System.out.println("You just have to calculate stuffs");
System.out.println("Note: You may need a calculator ");
System.out.println("Okay, let's start");
System.out.println("Follow every step carefully");
System.out.println("Note: If you are using a calculator, press 'equal to' ('=') button after every step ");
System.out.println("Step 1: Multiply your birth month by 5 ");
System.out.println("Step 2: Add 6 to the result");
System.out.println("Step 3: Multiply the result by 4");
System.out.println("Step 4: Add 9 to the result");
System.out.println("Step 5: Multiply the result by 5");
System.out.println("Step 6: Add your birth date to the result");
System.out.println("Now, enter the final result");
Scanner sc = new Scanner(System.in);
finalResult = sc.nextInt();
finalResult -= 165;
month = finalResult / 100;
date = finalResult % 100;
if (month == 1 || month == 3 || month == 5 || month == 7 || month ==8 || month == 10 || month == 12)
if(date > 31) {
System.out.println("Invalid Input");
System.exit(0);
}
if(month == 4 || month == 6 || month == 9 || month == 11)
if(date > 30){
System.out.println("Invalid Input");
System.exit(0);
}

switch(month){
case 1:
alphabeticalRepresentationOfMonth = "January";
break;
case 2: alphabeticalRepresentationOfMonth = "February";
break;
case 3: alphabeticalRepresentationOfMonth = "March";
break;
case 4: alphabeticalRepresentationOfMonth = "April";
break;
case 5: alphabeticalRepresentationOfMonth = "May";
break;
case 6: alphabeticalRepresentationOfMonth = "June";
break;
case 7: alphabeticalRepresentationOfMonth = "July";
break;
case 8: alphabeticalRepresentationOfMonth = "August";
break;
case 9: alphabeticalRepresentationOfMonth = "September";
break;
case 10: alphabeticalRepresentationOfMonth = "October";
break;
case 11: alphabeticalRepresentationOfMonth = "November";
break;
case 12: alphabeticalRepresentationOfMonth = "December";
break;
default:
alphabeticalRepresentationOfMonth = "NULL";
System.out.println("Invalid Input");
System.exit(0);

}
if(date >= 10 && date <= 20 )
suffix = "th";
else {
switch (date % 10) {
case 1:
suffix = "st";
break;
case 2:
suffix = "nd";
break;
case 3:
suffix = "rd";
break;
default:
suffix = "th";
break;
}
}
System.out.println("Enter your age: ");
year = 2019 - sc.nextInt();
if(year % 4 == 0){
if(year % 100 == 0){
if(year % 400 == 0)
flag = 1;
else
flag = 0;
}
else
flag = 1;
}
else
flag = 0;
if(flag == 1 && month == 2)
if (date > 29) {
System.out.println("Invalid Input");
System.exit(0);
}
if(flag == 0 && month == 2)
if(date > 28){
System.out.println("Inalid Input");
System.exit(0);
}
System.out.println("Your birthday is on " + date + suffix + " "+ alphabeticalRepresentationOfMonth + ", " + year);

}
}``````
Failed Tests

### Full Fraction class

Class for calculation with fractions

``````def gcd(a, b):
if a == b:
return a
elif a > b:
if a % b != 0:
return gcd(b, a % b)
else:
return b
else:
return gcd(b, a)

def lcm(a, b):
return a * b // gcd(a, b)

class Fraction:

def __init__(self, numerator, denominator):
g = gcd(numerator, denominator)
self.top = numerator // g
self.bottom = denominator // g

#Equality test

def __eq__(self, other):
first_num = self.top * other.bottom
second_num = other.top * self.bottom
return first_num == second_num

sum_denom = lcm(self.bottom, other.bottom)
first_num = sum_denom * self.top // self.bottom
second_num = sum_denom * other.top // other.bottom
sum_num = first_num + second_num
return Fraction(sum_num, sum_denom)

def __sub__(self, other):
dif_denom = lcm(self.bottom, other.bottom)
first_num = sum_denom * self.top // self.bottom
second_num = sum_denom * other.top // other.bottom
dif_num = first_num - second_num
return Fraction(dif_num, dif_denom)

def __mul__(self, other):
return Fraction(self.top * other.top, self.bottom * other.bottom)

def __truediv__(self, other):
return Fraction(self.top * other.bottom, self.bottom * other.top)

def __str__(self):
return str(self.top) + "/" + str(self.bottom)``````

### gavrashenko's Kumite #2

``````// TODO: Create method objectFreeze which works the same as native Object.freeze.
// !IMPORTANT: You haven't use Object.freeze during your task

function objectFreeze(obj) {
return Object.freeze(obj);
}``````