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.

### get height of binary tree

Given a binary tree defined as below, return the height of the tree.

``````class Node {
constructor(val) {
this.data = val;
this.left = null;
this.right = null;
}
}```

Example:(TBD)
``````
``````function treeHeight(node)
{
if (node == null)
return 0;
else
{
/* compute the height of each subtree */
var lheight = treeHeight(node.left);
var rheight = treeHeight(node.right);

/* use the larger one */
if (lheight > rheight)
{
return(lheight + 1);
}
else {
return(rheight + 1);
}
}
}``````

Fundamentals
Numbers
Data Types
Logic

### Write a method that returns a greater number.

Welcome to CodeWars!
``````public class Math
{
public int Max(int a, int b)
{
return (a > b) ? a : b;
}
}``````
Failed Tests

### wu850217's Kumite #2

``````# You can test with testthat (http://r-pkgs.had.co.nz/tests.html#test-structure)
# TODO: replace with your own tests (TDD), these are just here to demonstrate usage.

test_that("example", {
expect_equal(actual, expected)
})``````

### Once upon a time in the huge array

Write an implementation of a method:

• @param a - array of numbers, array length can be greater than 10 million.
• @return - array of numbers with no duplicates. The order of numbers in the original array must be preserved. The last element of the duplicates must be kept, e.g. for {2.0, 1.0, 4.0, 2.0, 3.0} the correct solution is {1.0, 4.0, 2.0, 3.0}, not {2.0, 1.0, 4.0, 3.0}!

In case there is an element less than 0.0 in the input array, output array{-1.0} should be given.
For example, for {2.0, 3.0, -1.0, 5.0} the processing should result {-1.0}.

Good luck...

``````import java.util.*;

class DeleteDuplicates {
public static double[] delete(double[] a) {

for(int i = 0; i < a.length / 2; i++) {
double temp = a[i];
a[i] = a[a.length - i - 1];
a[a.length - i - 1] = temp;
}

for (double v : a) {
if(v < 0.0)
return new double[]{-1.0};
}

List<Double> list = new ArrayList<>(set);
Collections.reverse(list);

double[] array_here = list.stream().mapToDouble(Double::doubleValue).toArray();

//incorrect (too long and witout accuracy)

return array_here;
}
}``````

Fundamentals
Strings
Data Types
Logic

### Write a function that returns string:

"Fizz" when the number is divisible by 3.
"Buzz" when the number is divisible by 5.
"FizzBuzz" when the number is divisible by 3 and 5.

``````public class FizzBuzz
{
public string GetOutput(int number)
{
if ((number % 3 == 0) && (number % 5 == 0))
return "FizzBuzz";

else if (number % 3 == 0)
return "Fizz";

else if (number % 5 == 0)
return "Buzz";

else return number.ToString();
}
}``````

Write the function `optimal_gifts(gifts: int, recipients: int) -> int`
You are given `gifts` number of gifts and `recipients` number of recipients.

Return the maximum number of recipients that can receive 8 gifts under the following conditions:

• No recipient can recieve no gifts
• No recipient can recieve 4 gifts

Examples:

• `optimal_gifts(8, 2)` returns 0
• `optimal_gifts(12, 2)` returns 0
• `optimal_gifts(8, 1)` returns 1
• `optimal_gifts(24, 2)` returns 2
• `optimal_gifts(24, 3)` returns 3
• `optimal_gifts(24, 4)` returns 2
``````def optimal_gifts(gifts: int, recipients: int) -> int:
kids = [1 for _ in range(gifts)]
for i in range(recipients):
while (gifts > 0 and kids[i] < 8):
kids[i] += 1

eigths = sum([1 if kid == 8 else 0 for kid in kids])

if 4 in kids:
eigths -= 1

return eigths``````

### Do we have programmer's day today?

Always forget how to exact determine programmer's day. Some code may help do it exactly and without heavy calculations.

``````# How to check that target date is Programmer's day?

def is_programmers_day(date):
return date.timetuple().tm_yday == 256``````
Failed Tests

### Split Strings

``````package kata

func Solution(str string) []string {
var res []string
if len(str) % 2 != 0 {
str += "_"
}
for i := 0; i < len(str); i+=2 {
res = append(res, str[i:i+2])
}
return res
}``````

### Approximate PI using random function

``````import random

def approximate_pi(n):
# n - number of generated points, more points => more accuracy
number_of_points_in_circle = 0
total_number_of_points = 0

for _ in range(n):
x = random.uniform(0, 1)
y = random.uniform(0, 1)

# sqrt(x^2 + y^2) < 1 => (x,y) inside circle with r = 1; x^2 + y^2 < 1 => (x,y) inside circle
if (x**2 + y**2 < 1):
number_of_points_in_circle += 1

total_number_of_points += 1

# Pi * r^2 / (2r)^2 = number_of_points_in_circle / total_number_of_points (ratio of the area of a circle with radius r to the area of a square with side = 2r)
# r=1 => Pi = number_of_points_in_circle * 4 / total_number_of_points
return (number_of_points_in_circle * 4) / total_number_of_points``````

### Testing

Simple test to see how creating Kumites work

This function should return the sum of a and b.

(1,2) => 3
(5,9) => 14
(-3,8) => 5

``````def add(a, b):
return a + b``````