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.
Prints "Hello Bash" and any parameters to stdout.
#!/bin/bash echo Hello Bash! if [ $# -eq 1 ]; then echo "Hello, $1!" else echo "No parameters found." fi
1 + #!/bin/bash
2 + 1 1 echo Hello Bash!
4 + 5 + if [ $# -eq 1 ]; then
6 + echo "Hello, $1!"
7 + else
8 + echo "No parameters found."
9 + fi
# TODO: replace with your own tests (TDD). An example to get you started is included below. # run the solution and store its result output = run_shell args: ['Kumite'] describe "Solution" do it "should return the argument passed in" do expect(output).to include('Hello Bash!') end end
1 1 # TODO: replace with your own tests (TDD). An example to get you started is included below.
2 2 3 3 # run the solution and store its result
4 − output = run_shell
4 + output = run_shell args: ['Kumite']
5 5 6 6 describe "Solution" do
7 7 it "should return the argument passed in" do
8 8 expect(output).to include('Hello Bash!')
9 9 end
10 10 end
Recent Moves:
Shows how to use bash kta and how to create simple tests
echo Hello Bash!
# TODO: replace with your own tests (TDD). An example to get you started is included below.
# run the solution and store its result
output = run_shell
describe "Solution" do
it "should return the argument passed in" do
expect(output).to include('Hello Bash!')
end
end
Recent Moves:
function getMin(list) { x = Math.min(...list.filter(i => i > 0)); return x !== Infinity ? x : 0 }
1 1 function getMin(list) {
2 − let ret = list.reduce((prev, curr) => {
3 − if (curr <= 0) return prev;
4 − return (prev <= 0) ? curr : Math.min(curr, prev);
5 − }, -1);
6 − return ret > 0 ? ret : 0;
2 + x = Math.min(...list.filter(i => i > 0));
3 + return x !== Infinity ? x : 0
7 7 }
The function should find the smallest (positive) number in the array.
The array can contain the following values:
- Positive number
- Negavitve number
0
-
Null
value
If no number is found, you should return 0
Note: Zero is also counted as a positive number.
#Examples
[1, 2, 3, 4] => 1
[-2, 0, 4] => 0
[-2, -5] => 0
describe("Solution", function(){ it("test1", function(){ var list = [0, 1, 1, 3]; Test.assertEquals(getMin(list), 1, "test fails"); }); it("test2", function(){ var list = [7, 2, null, 3, 0, 10]; Test.assertEquals(getMin(list), 2, "test fails"); }); it("test3", function(){ var list = [null, -2]; Test.assertEquals(getMin(list), 0, "test fails"); }); it("test4", function(){ var list = [Number.MAX_VALUE]; Test.assertEquals(getMin(list), Number.MAX_VALUE, "test fails"); }); it("test5", function(){ var list = [0.5,7, 2, null, 3, 0, 10]; Test.assertEquals(getMin(list), 0.5, "test fails"); }); it("dynamic test", function(){ var minValue = null; var list = []; for(var i = 20; i > 0; i--){ var toAdd = (Math.random()*1000 - 500); if(toAdd >= 0 && (minValue === null || minValue > toAdd)) minValue = toAdd; list.push(minValue); } Test.assertEquals(getMin(list), minValue, "test fails"); }); it("long dynamic test", function(){ var minValue = null; var list = []; for(var i = 100; i > 0; i--){ var toAdd = (Math.random()*1000 - 500); if(toAdd >= 0 && (minValue === null || minValue > toAdd)) minValue = toAdd; list.push(minValue); } Test.assertEquals(getMin(list), minValue, "test fails"); }); });
… Expand 1 1 describe("Solution", function(){
2 2 it("test1", function(){
3 3 var list = [0, 1, 1, 3];
4 4 Test.assertEquals(getMin(list), 1, "test fails");
5 5 });
6 6 it("test2", function(){
7 7 var list = [7, 2, null, 3, 0, 10];
8 8 Test.assertEquals(getMin(list), 2, "test fails");
9 9 });
10 10 it("test3", function(){
11 11 var list = [null, -2];
12 12 Test.assertEquals(getMin(list), 0, "test fails");
13 13 });
14 14 it("test4", function(){
15 15 var list = [Number.MAX_VALUE];
16 16 Test.assertEquals(getMin(list), Number.MAX_VALUE, "test fails");
17 17 });
18 18 it("test5", function(){
19 19 var list = [0.5,7, 2, null, 3, 0, 10];
20 20 Test.assertEquals(getMin(list), 0.5, "test fails");
21 21 });
22 + it("dynamic test", function(){
23 + var minValue = null;
24 + var list = [];
25 + for(var i = 20; i > 0; i--){
26 + var toAdd = (Math.random()*1000 - 500);
27 + if(toAdd >= 0 && (minValue === null || minValue > toAdd))
28 + minValue = toAdd;
29 + list.push(minValue);
30 + }
31 + Test.assertEquals(getMin(list), minValue, "test fails");
32 + });
33 + 34 + it("long dynamic test", function(){
35 + var minValue = null;
36 + var list = [];
37 + for(var i = 100; i > 0; i--){
38 + var toAdd = (Math.random()*1000 - 500);
39 + if(toAdd >= 0 && (minValue === null || minValue > toAdd))
40 + minValue = toAdd;
41 + list.push(minValue);
42 + }
43 + Test.assertEquals(getMin(list), minValue, "test fails");
44 + });
22 22 });
var getMin = function (list){ var list = (!list) ? 0 : list.filter(function(v){ return (v > 0 && v < Number.MAX_VALUE); }); return Math.min.apply(null,list) | 0; }
1 1 var getMin = function (list){
2 − var min = Number.MAX_VALUE;
3 − for (var i = 0; i < list.length; i++) {
4 − if (+list[i] <= 0) {
5 − continue;
6 − }
7 − min = Math.min(min, +list[i]);
8 − }
9 − return min = min === Number.MAX_VALUE ? 0 : min;
2 + var list = (!list) ? 0 : list.filter(function(v){ return (v > 0 && v < Number.MAX_VALUE); });
3 + return Math.min.apply(null,list) | 0;
10 10 }
describe("Solution", function(){ it("test1", function(){ var list = [0, 1, 1, 3]; Test.assertEquals(getMin(list), 1, "test fails"); }); it("test2", function(){ var list = [7, 2, null, 3, 0, 10]; Test.assertEquals(getMin(list), 2, "test fails"); }); it("test3", function(){ var list = [null, -2]; Test.assertEquals(getMin(list), 0, "test fails"); }); it("test4", function(){ var list = [5,null, -2, {a:"5"}, [1,2,3],3]; Test.assertEquals(getMin(list), 3, "test fails"); }); });
… Expand 1 1 describe("Solution", function(){
2 2 it("test1", function(){
3 3 var list = [0, 1, 1, 3];
4 4 Test.assertEquals(getMin(list), 1, "test fails");
5 5 });
6 6 it("test2", function(){
7 7 var list = [7, 2, null, 3, 0, 10];
8 8 Test.assertEquals(getMin(list), 2, "test fails");
9 9 });
10 10 it("test3", function(){
11 11 var list = [null, -2];
12 12 Test.assertEquals(getMin(list), 0, "test fails");
13 13 });
14 + it("test4", function(){
15 + var list = [5,null, -2, {a:"5"}, [1,2,3],3];
16 + Test.assertEquals(getMin(list), 3, "test fails");
17 + });
14 14 });
Сan not be stored list in the memory
(ns quicksort.core)
(defn quick-sort [nums]
(if (< (count nums) 2) nums
(concat
(quick-sort (filter #(< % (first nums)) nums))
(filter #(= % (first nums)) nums)
(quick-sort (filter #(> % (first nums)) nums)))))
(ns quicksort.test
(:require [clojure.test :refer :all]
[quicksort.core :refer [quick-sort]]))
(deftest quick-sort-test
(is (= (quick-sort '(2 3 1)) '(1 2 3)))
(is (= (quick-sort '(9 -1 -2 10)) '(-2 -1 9 10)))
(is (= (quick-sort '(1 2 666 233 0 8 34 -1)) '(-1 0 1 2 8 34 233 666))))
import java.util.*; public class MatchingBrackets { static final Map<Character, Character> brackets = new HashMap<Character, Character>() {{ put(')','('); put('}','{'); put(']','['); }}; public static boolean isBalanced(final String braces) { final Stack<Character> stack = new Stack<>(); for (final char brace : braces.toCharArray()) { if (!stack.isEmpty() && stack.peek() == brackets.get(brace)) { stack.pop(); } else { stack.push(brace); } } return stack.isEmpty(); } }
1 1 import java.util.*;
2 2 3 3 public class MatchingBrackets {
4 4 5 − public static boolean isBalanced(String braces) {
6 − Stack<String> stack = new Stack<>();
7 − Map<String, String> enclosing = new HashMap<>();
8 − enclosing.put(")","(");
9 − enclosing.put("}","{");
10 − enclosing.put("]","[");
11 − for (char brace : braces.toCharArray()) {
12 − final String strBrace = Character.toString(brace);
13 − if (!stack.isEmpty() && stack.peek().equals(enclosing.get(strBrace))) {
14 − stack.pop();
15 − } else {
16 − stack.push(strBrace);
17 − }
18 − }
19 − return stack.isEmpty();
5 + static final Map<Character, Character> brackets = new HashMap<Character, Character>() {{
6 + put(')','(');
7 + put('}','{');
8 + put(']','[');
9 + }};
10 + 11 + public static boolean isBalanced(final String braces) {
12 + final Stack<Character> stack = new Stack<>();
13 + for (final char brace : braces.toCharArray()) {
14 + if (!stack.isEmpty() && stack.peek() == brackets.get(brace)) {
15 + stack.pop();
16 + } else {
17 + stack.push(brace);
18 + }
20 20 }
20 + return stack.isEmpty();
21 + }
21 21 }