Search
• ###### 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.

### Generate Prime Numbers

Code
Diff
• ``````import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Primes {
public static boolean isPrime(int n) {
if (n == 2)
return true;

if (n % 2 == 0) return false;

for (int i = 3; i * i <= n; i += 2) {
if (n % i == 0)
return false;
}
return true;
}

public static List<Integer> generatePrimes(int min, int max) {
if (!(min > 0 && max > 0))
return null;

return IntStream.range(min, max)
.filter(e -> isPrime(e))
.boxed()
.collect(Collectors.toList());
}

}``````
•  1 − ```import java.util.*; ``` 1 + ```import java.util.List; ``` 2 + ```import java.util.stream.Collectors; ``` 3 + ```import java.util.stream.IntStream; ``` 2 2 3 3 ```public class Primes { ``` 4 − ``` public static List generatePrimes(int min, int max) { ``` 5 − ``` List primes = new ArrayList(); ``` 6 − ``` boolean isPrime = false; ``` 7 − ``` ``` 8 − ``` if((min > max) || min < 0 || max <= 0) { ``` 9 − ``` return null; ``` 10 − ``` } ``` 11 − ``` ``` 12 − ``` for(int i = min; i <= max; i++) { ``` 13 − ``` long endLimit = (long)Math.floor(Math.sqrt(i)); ``` 14 − ``` isPrime = true; ``` 15 − ``` for(long j = 2; j <= endLimit; j++) { ``` 16 − ``` if (i % j == 0) { ``` 17 − ``` isPrime = false; ``` 18 − ``` break; ``` 6 + ``` public static boolean isPrime(int n) { ``` 7 + ``` if (n == 2) ``` 8 + ``` return true; ``` 9 + 10 + ``` if (n % 2 == 0) return false; ``` 11 + 12 + ``` for (int i = 3; i * i <= n; i += 2) { ``` 13 + ``` if (n % i == 0) ``` 14 + ``` return false; ``` 19 19 ``` } ``` 20 − ``` } ``` 21 − ``` ``` 22 − ``` if(isPrime) { ``` 23 − ``` primes.add(i); ``` 24 − ``` } ``` 16 + ``` return true; ``` 25 25 ``` } ``` 26 26 ``` ``` 27 − ``` return primes; ``` 28 − ``` } ``` 19 + ``` public static List generatePrimes(int min, int max) { ``` 20 + ``` if (!(min > 0 && max > 0)) ``` 21 + ``` return null; ``` 22 + 23 + ``` return IntStream.range(min, max) ``` 24 + ``` .filter(e -> isPrime(e)) ``` 25 + ``` .boxed() ``` 26 + ``` .collect(Collectors.toList()); ``` 27 + ``` } ``` 28 + 29 29 ```} ```

### HashMap Example

Hashes
Data Structures
Code
Diff
• ``````/* HashMap Example */

import java.util.*;
import java.lang.*;
import java.io.*;

class HashMapDemo
{
public static void main (String[] args) throws java.lang.Exception {
Map<Integer, Integer> map = new HashMap<Integer, Integer>() {{
put(1, 1);
put(2, 1);
put(3, 1);
put(4, 1);
put(5, 1);
put(6, 1);
}};

map.entrySet().stream().forEach(e -> System.out.println(e.getKey() + " " + e.getValue()));
}
}``````
•  1 1 ```/* HashMap Example */ ``` 2 2 ``` ``` 3 3 ```import java.util.*; ``` 4 4 ```import java.lang.*; ``` 5 5 ```import java.io.*; ``` 6 6 ``` ``` 7 7 ```class HashMapDemo ``` 8 8 ```{ ``` 9 − ``` public static void main (String[] args) throws java.lang.Exception ``` 10 − ``` { ``` 11 − ``` Map map = new HashMap(); ``` 12 − ``` map.put(1, 1); ``` 13 − ``` map.put(2, 1); ``` 14 − ``` map.put(3, 1); ``` 15 − ``` map.put(4, 1); ``` 16 − ``` map.put(5, 1); ``` 17 − ``` map.put(6, 1); ``` 18 − ``` ``` 19 − ``` for(Map.Entry entry : map.entrySet()) { ``` 20 − ``` int key = entry.getKey(); ``` 21 − ``` int value = entry.getValue(); ``` 22 − ``` System.out.println(key + " " + value); ``` 23 − ``` } ``` 24 − ``` } ``` 9 + ``` public static void main (String[] args) throws java.lang.Exception { ``` 10 + ``` Map map = new HashMap() {{ ``` 11 + ``` put(1, 1); ``` 12 + ``` put(2, 1); ``` 13 + ``` put(3, 1); ``` 14 + ``` put(4, 1); ``` 15 + ``` put(5, 1); ``` 16 + ``` put(6, 1); ``` 17 + ``` }}; ``` 18 + 19 + ``` map.entrySet().stream().forEach(e -> System.out.println(e.getKey() + " " + e.getValue())); ``` 20 + ``` } ``` 25 25 ```} ```

### Collatz sequence

Sequences
Arrays
Code
Diff
• ``````module Collatz where

collatz :: Int -> [Int]
collatz = iterate next
where next n | even n = n `div` 2
| odd n = n * 3 + 1``````
•  1 1 ```module Collatz where ``` 2 2 3 3 ```collatz :: Int -> [Int] ``` 4 − ```collatz n = n : collatz next ``` 5 − ``` where next | even n = n `div` 2 ``` 6 − ``` | odd n = n * 3 + 1 ``` 4 + ```collatz = iterate next ``` 5 + ``` where next n | even n = n `div` 2 ``` 6 + ``` | odd n = n * 3 + 1 ```

### Euclidean distance

Code
Diff
• ``````var merge = function(array1, array2, callbackFN){
return callbackFN(array1,array2);
}

function callbackFN(a,b) {
return a.map(function(c,i){return c + b[i];});
}

var x = merge([1, 2, 3, 4], [5, 6, 7, 8], callbackFN);
console.log(x);   //x should now equal [6, 8, 10, 12].
``````
•  1 − ```var merge = function(array1, array2, callback){ ``` 2 − ``` var array3 = []; ``` 3 − 4 − ``` if (array1.length !== array2.length) { ``` 5 − ``` console.log("Array length mismatch"); ``` 6 − ``` return new Error("Array length mismatch"); ``` 7 − ``` } else { ``` 8 − ``` length = array1.length; ``` 9 − ``` } ``` 10 − 11 − ``` for (var i = 0; i < length; i++) { ``` 12 − ``` array3[i] = callback(array1[i], array2[i]); ``` 13 − ``` } ``` 14 − ``` return array3; ``` 1 + ```var merge = function(array1, array2, callbackFN){ ``` 2 + ``` return callbackFN(array1,array2); ``` 15 15 ```} ``` 16 16 17 − ```var x = merge([1, 2, 3, 4], [5, 6, 7, 8], function(a, b){ ``` 18 − ``` return a + b; ``` 19 − ```}); ``` 20 − 21 − ```//x should now equal [6, 8, 10, 12]. ``` 22 − 23 − ```var euclid = function(coords1, coords2){ ``` 24 − ``` //Your code here. ``` 25 − ``` //You should not use any loops and should ``` 26 − ``` //instead use your original merge function. ``` 5 + ```function callbackFN(a,b) { ``` 6 + ``` return a.map(function(c,i){return c + b[i];}); ``` 27 27 ```} ``` 28 28 29 − ```var y = euclid([1.2, 3.67], [2.0, 4.4]); ``` 30 − 31 − ```//y should now equal approximately 1.08. ``` 9 + ```var x = merge([1, 2, 3, 4], [5, 6, 7, 8], callbackFN); ``` 10 + ```console.log(x); //x should now equal [6, 8, 10, 12]. ```

Recent Moves:

Failed Tests

### Find Duplicates Using Reduce

Arrays
Map/Reduce
Algorithms

For loops are commonly overused when other Javascript methods can lead to a cleaner and faster solution. A common example would be finding duplicates in an array.

This function called duplicates takes an array of numbers and returns a new array with the numbers duplicated in the original array ordered by value.

Your goal is to refactor this code to still find duplicates in an array and return those duplicates in a new array, but no longer use a for loop.

Note: numbers and their corresponding string representations should not be treated as duplicates (i.e., '1' !== 1).

``````function duplicates(arr) {
var out = [];
for(var x=0;x<arr.length-1;x++)
{
var ch = arr[x];
for(var y=x+1;y<arr.length;y++)
{
var comp = arr[y];
if (comp === ch && out.indexOf(comp) === -1)
{
out.push(comp);
break;
}
}
}
out.sort();
return out;
}``````

### Fizz Buzzy Goblin

Ha doesn't really work but yeah

Code
Diff
• ``````function fizzbuzzy(n) {
var cones = 1;
for (i = 0; i < n; i++){
!(i % 5) && cones++;
!(i % 3) && cones++;
}
return cones;
}
``````
•  1 1 ```function fizzbuzzy(n) { ``` 2 2 ``` var cones = 1; ``` 3 3 ``` for (i = 0; i < n; i++){ ``` 4 − ``` if (i % 5 === 0) cones++; ``` 5 − ``` if (i % 3 === 0) cones++; ``` 4 + ``` !(i % 5) && cones++; ``` 5 + ``` !(i % 3) && cones++; ``` 6 6 ``` } ``` 7 7 ``` return cones; ``` 8 8 ```} ```

Recent Moves: