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.

### Return Largest Possible Number

Code
Diff
• ``````import java.util.*;

class Solution {

public static String largestNumber(final Integer[] nums) {

Arrays.sort(nums, (a,b) -> (""+b+a).compareTo(""+a+b) );

String result = "";
for (final Integer num : nums) {
result += num;
}

return result;
}
}``````
• import java.util.*;
• class Solution {
• public static String largestNumber(final Integer[] nums) {
• Arrays.sort(nums, new Comparator<Integer>() {
• @Override
• public int compare(final Integer a, final Integer b) {
• return (""+b+a).compareTo(""+a+b);
• }
• });
• Arrays.sort(nums, (a,b) -> (""+b+a).compareTo(""+a+b) );
• String result = "";
• for (final Integer num : nums) {
• result += num;
• }
• return result;
• }
• }

### Hello, Ruby!

Code
Diff
• ``````# What are all the ways to output a string in Ruby?
def hello_ruby
greet = "Hello Ruby!"

print           greet, "\n"
puts            greet
print           "#{greet}\n"
puts            "Hello Ruby!"
\$stdout.write   greet + "\n"
\$stdout.puts    greet
\$stdout.print   greet, "\n"
\$stdout <<      greet + "\n"
(greet+"\n").each_char {|c| print c}
end``````
• # What are all the ways to output a string in Ruby?
• def hello_ruby
• greet = "Hello Ruby!"
• print greet, "\n"
• puts greet
• print "#{greet}\n"
• puts "#{greet}"
• puts "Hello Ruby!"
• \$stdout.write greet + "\n"
• \$stdout.puts greet
• \$stdout.print greet, "\n"
• \$stdout << greet + "\n"
• (greet+"\n").each_char {|c| print c}
• end

### Find the nth Fibonacci number

Code
Diff
• ``````def fib(x):
fib = [1,1]
for x in range(x-1):
fib.append(fib[-2]+fib[-1])
return fib[-1]``````
• def _fib(n):
• k = n.bit_length()-1
• x0, x1 = 1, 0
• y0, y1 = 0, 1
• for i in range(k, -1, -1):
• y2 = y0*y0
• y0, y1 = 2*y0*y1+y2, y2+y1*y1
• if (n>>i)&1:
• xy = x0*y0
• y0, y1 = x0*y1+x1*y0+xy, xy+x1*y1
• return y0
• def fib(n):
• return _fib(n+1)
• def fib(x):
• fib = [1,1]
• for x in range(x-1):
• fib.append(fib[-2]+fib[-1])
• return fib[-1]

### Hello PHP!

Fundamentals
Code
Diff
• ``````function greet_language(string \$lang = "PHP"): string
{
return "Hello {\$lang}!";
}
``````
• function greet_language(\$lang = "PHP") {
• print "Hello \$lang!\n";
• function greet_language(string \$lang = "PHP"): string
• {
• return "Hello {\$lang}!";
• }
• greet_language();
• greet_language("Javascript");
• greet_language("Ruby");
Failed Tests

### Listing All Files in a Directory

Code
Diff
• ``````import os
print(os.listdir('directorypath'))# Replace 'directorypath' with path to directory``````
• import glob
• print(glob.glob('directorypath'))# Replace 'directorypath' with path to directory
• import os
• print(os.listdir('directorypath'))# Replace 'directorypath' with path to directory

### Matching Brackets

Stacks
Arrays
Data Types
Code
Diff
• ``````import java.util.*;

public class MatchingBrackets {
public static final class Brace {

static final Map<Character, Character> enclosing = new HashMap<>();
static {
enclosing.put(')','(');
enclosing.put('}','{');
enclosing.put(']','[');
}

private Character braceChar;

public Brace(Character braceChar) {
this.braceChar = braceChar;
}

public boolean isEnclosingTo(Brace brace) {
if (brace == null) {
return false;
}
return brace.braceChar.equals(enclosing.get(this.braceChar));
}
}

public static final class BraceStack {
private Stack<Brace> stack = new Stack<>();

public Brace getLastBraceOnStack() {
if (stack.isEmpty()) {
return null;
}
return stack.peek();
}

public Brace pop() {
return stack.pop();
}

public void push(Brace brace) {
stack.push(brace);
}

public boolean isEmpty() {
return stack.isEmpty();
}
}
public static boolean isBalanced(String braces) {
BraceStack braceStack = new BraceStack();
for (char nextChar : braces.toCharArray()) {
final Brace nextBrace = new Brace(nextChar);

if (nextBrace.isEnclosingTo(braceStack.getLastBraceOnStack())) {
braceStack.pop();
} else {
braceStack.push(nextBrace);
}

}
return braceStack.isEmpty();
}
}``````
• import java.util.*;
• public class MatchingBrackets {
• public static final class Brace {
• static final Map<Character, Character> enclosing = new HashMap<>();
• static {
• enclosing.put(')','(');
• enclosing.put('}','{');
• enclosing.put(']','[');
• }
• private Character braceChar;
• public Brace(Character braceChar) {
• this.braceChar = braceChar;
• }
• public boolean isEnclosingTo(Brace brace) {
• if (brace == null) {
• return false;
• }
• return brace.braceChar.equals(enclosing.get(this.braceChar));
• }
• }
• public static boolean isBalanced(String braces) {
• Stack<Brace> stack = new Stack<>();
• public static final class BraceStack {
• private Stack<Brace> stack = new Stack<>();
• public Brace getLastBraceOnStack() {
• if (stack.isEmpty()) {
• return null;
• }
• return stack.peek();
• }
• public Brace pop() {
• return stack.pop();
• }
• public void push(Brace brace) {
• stack.push(brace);
• }
• public boolean isEmpty() {
• return stack.isEmpty();
• }
• }
• public static boolean isBalanced(String braces) {
• BraceStack braceStack = new BraceStack();
• for (char nextChar : braces.toCharArray()) {
• final Brace nextBrace = new Brace(nextChar);
• if (!stack.isEmpty()) {
• Brace lastBraceOnStack = stack.peek();
• if (nextBrace.isEnclosingTo(lastBraceOnStack)) {
• stack.pop();
• continue;
• }
• if (nextBrace.isEnclosingTo(braceStack.getLastBraceOnStack())) {
• braceStack.pop();
• } else {
• braceStack.push(nextBrace);
• }
• stack.push(nextBrace);
• }
• return stack.isEmpty();
• return braceStack.isEmpty();
• }
• }