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.
function square_n_sum($array_of_numbers) { $acc = 0; foreach ($array_of_numbers as $el) { $acc += $el ^ 2; } return $acc; } echo square_n_sum(array(1,2,3,5,6)); // Should return 75 echo "<br />"; echo square_n_sum(array(1,2)); // Should return 5 echo "<br />"; echo square_n_sum(array(3,4)); // Should return 25 echo "<br />"; echo square_n_sum(array(1,2,3,4)); // Should return 30 echo "<br />"; echo square_n_sum(array(1,2,3,4,5,6,7,8,9,99)); // Should return 10086
- function square_n_sum($array_of_numbers) {
for ($i = 0; $i < sizeof($array_of_numbers); $i++) {$array_of_numbers[$i] = $array_of_numbers[$i] ** 2;- $acc = 0;
- foreach ($array_of_numbers as $el) {
- $acc += $el ^ 2;
- }
$sum_of_squared_numbers = 0;for ($i = 0; $i < sizeof($array_of_numbers); $i++) {$sum_of_squared_numbers += $array_of_numbers[$i];}return $sum_of_squared_numbers;- return $acc;
- }
- echo square_n_sum(array(1,2,3,5,6)); // Should return 75
- echo "<br />";
- echo square_n_sum(array(1,2)); // Should return 5
- echo "<br />";
- echo square_n_sum(array(3,4)); // Should return 25
- echo "<br />";
- echo square_n_sum(array(1,2,3,4)); // Should return 30
- echo "<br />";
- echo square_n_sum(array(1,2,3,4,5,6,7,8,9,99)); // Should return 10086
var merge = function(array1, array2, callbackFN){ return callbackFN(array1,array2); } function callbackFN(a,b) { if(Array.isArray(a) && Array.isArray(b) && (a.length === b.length)){ return a.map(function(c,i){ return c + b[i]; }); } else { return 'both inputs must be Array and same size of elements'; } } var x = merge([1, 3, 4], [5, 6, 7, 8], callbackFN); console.log(x); //x should now equal [6, 8, 10, 12].
- var merge = function(array1, array2, callbackFN){
- return callbackFN(array1,array2);
- }
- function callbackFN(a,b) {
return a.map(function(c,i){return c + b[i];});- if(Array.isArray(a) && Array.isArray(b) && (a.length === b.length)){
- return a.map(function(c,i){ return c + b[i]; });
- } else {
- return 'both inputs must be Array and same size of elements';
- }
- }
var x = merge([1, 2, 3, 4], [5, 6, 7, 8], callbackFN);- var x = merge([1, 3, 4], [5, 6, 7, 8], callbackFN);
- console.log(x); //x should now equal [6, 8, 10, 12].
import java.util.*; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.IntStream; /** Time Complexity : O(N) Space Complexity : O(N) */ class MaxOccurence { public static int findMax(int[] nums) { Optional<Map.Entry<Integer, List<Integer>>> max = IntStream.of(nums) .boxed() .collect(Collectors.groupingBy(num -> num)) .entrySet() .stream() .max((e1, e2) -> e1.getValue().size() - e2.getValue().size()); return max.isPresent() ? max.get().getKey() : -1; } }
- import java.util.*;
- import java.util.List;
- import java.util.Map;
- import java.util.Optional;
- import java.util.stream.Collectors;
- import java.util.stream.IntStream;
- /**
- Time Complexity : O(N)
- Space Complexity : O(N)
- */
- class MaxOccurence {
- public static int findMax(int[] nums) {
return findMaxOccurenceLinkedHashMap(nums);- Optional<Map.Entry<Integer, List<Integer>>> max = IntStream.of(nums)
- .boxed()
- .collect(Collectors.groupingBy(num -> num))
- .entrySet()
- .stream()
- .max((e1, e2) -> e1.getValue().size() - e2.getValue().size());
- return max.isPresent() ? max.get().getKey() : -1;
- }
private static int findMaxOccurenceLinkedHashMap(int[] nums) {int maxKey = 0, maxNum = 0;if(nums.length < 1) return -1;if(nums.length == 1) return nums[0];Map<Integer, Integer> counts = new LinkedHashMap<Integer, Integer>(nums.length);for(int i = 0, len = nums.length; i < len; i++) {if(!counts.containsKey(nums[i])) {counts.put(nums[i], 1);} else {counts.put(nums[i], (counts.get(nums[i]) + 1));}}for (Map.Entry<Integer, Integer> entry : counts.entrySet()) {if (entry.getValue() > maxNum) {maxKey = entry.getKey();maxNum = entry.getValue();}}return maxKey;}- }
import java.util.*; import org.junit.Ignore; import org.junit.Test; import static org.junit.Assert.*; public class MaxOccurenceTest { @Test public void test1() { int[] nums = {1, 2, 9, 3, 4, 3, 3, 1, 2, 4, 5, 3, 8, 3, 9, 0, 3, 2}; assertEquals(3, MaxOccurence.findMax(nums)); } @Ignore @Test public void test2() { int[] nums = {5, 4, 6 ,7, 9, 8, 2, 4, 3, 6, 5, 8, 6, 1, 2, 5, 3, 4, 7, 9, 0, 8, 5, 7, 3, 4, 6, 1, 3}; // there is no instruction what of the numbers should be printed first if there are many max numbers in the row assertEquals(5, MaxOccurence.findMax(nums)); } @Test public void test3() { int[] nums = {8}; assertEquals(8, MaxOccurence.findMax(nums)); } @Test public void test4() { int[] nums = {}; assertEquals(-1, MaxOccurence.findMax(nums)); } @Test public void test5() { int[] nums = {2, 2, 3, 3, 4, 4, 5, 5, 6, 6}; assertEquals(2, MaxOccurence.findMax(nums)); } @Test public void test6() { int[] nums = {2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5}; assertEquals(5, MaxOccurence.findMax(nums)); } }
- import java.util.*;
- import org.junit.Ignore;
- import org.junit.Test;
- import static org.junit.Assert.*;
- public class MaxOccurenceTest {
- @Test
- public void test1() {
- int[] nums = {1, 2, 9, 3, 4, 3, 3, 1, 2, 4, 5, 3, 8, 3, 9, 0, 3, 2};
- assertEquals(3, MaxOccurence.findMax(nums));
- }
- @Ignore
- @Test
- public void test2() {
- int[] nums = {5, 4, 6 ,7, 9, 8, 2, 4, 3, 6, 5, 8, 6, 1, 2, 5, 3, 4, 7, 9, 0, 8, 5, 7, 3, 4, 6, 1, 3};
- // there is no instruction what of the numbers should be printed first if there are many max numbers in the row
- assertEquals(5, MaxOccurence.findMax(nums));
- }
- @Test
- public void test3() {
- int[] nums = {8};
- assertEquals(8, MaxOccurence.findMax(nums));
- }
- @Test
- public void test4() {
- int[] nums = {};
- assertEquals(-1, MaxOccurence.findMax(nums));
- }
- @Test
- public void test5() {
- int[] nums = {2, 2, 3, 3, 4, 4, 5, 5, 6, 6};
- assertEquals(2, MaxOccurence.findMax(nums));
- }
- @Test
- public void test6() {
- int[] nums = {2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5};
- assertEquals(5, MaxOccurence.findMax(nums));
- }
- }
/* 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())); } }
- /* 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>();map.put(1, 1);map.put(2, 1);map.put(3, 1);map.put(4, 1);map.put(5, 1);map.put(6, 1);for(Map.Entry<Integer, Integer> entry : map.entrySet()) {int key = entry.getKey();int value = entry.getValue();System.out.println(key + " " + value);}}- 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()));
- }
- }
import org.junit.Test; import static org.junit.Assert.assertEquals; import org.junit.runners.JUnit4; import java.util.*; public class MockTest { @Test public void test() { assertEquals(1, 1); } }
- import org.junit.Test;
- import static org.junit.Assert.assertEquals;
- import org.junit.runners.JUnit4;
- import java.util.*;
- public class MockTest {
- @Test
- public void test() {
- assertEquals(1, 1);
- }
- }
module Collatz where collatz :: Int -> [Int] collatz = iterate next where next n | even n = n `div` 2 | odd n = n * 3 + 1
- module Collatz where
- collatz :: Int -> [Int]
collatz n = n : collatz nextwhere next | even n = n `div` 2| odd n = n * 3 + 1- collatz = iterate next
- where next n | even n = n `div` 2
- | odd n = n * 3 + 1
Ha doesn't really work but yeah
function fizzbuzzy(n) { var cones = 1; for (i = 0; i < n; i++){ !(i % 5) && cones++; !(i % 3) && cones++; } return cones; }
- function fizzbuzzy(n) {
- var cones = 1;
- for (i = 0; i < n; i++){
if (i % 5 === 0) cones++;if (i % 3 === 0) cones++;- !(i % 5) && cones++;
- !(i % 3) && cones++;
- }
- return cones;
- }