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.
// slightly better performance, although still not great function pair(arr) { return arr.reduce((acc,no) => no < 0 && arr.includes(-no) ? acc.concat([no, -no]) : acc,[]) }- // slightly better performance, although still not great
- function pair(arr) {
for (var a of arr)if (a < 0 && arr.includes(-a))return [a, -a]- return arr.reduce((acc,no) => no < 0 && arr.includes(-no) ? acc.concat([no, -no]) : acc,[])
- }
const missing = (list1,list2) => list2.filter(item => !list1.includes(item));function missing() { cat $1 <(cat $1 $2 ) <(cat $2 $1 | sort | uniq -c | tr -d ' ' | grep '^1' | sed 's/1//') | sort | uniq -c | tr -d ' ' | grep '^2' | sed 's/2//'; }- const missing = (list1,list2) => list2.filter(item => !list1.includes(item));
const seed = Array .from({length:10}, () => String.fromCharCode(32+Math.round(Math.random()*90))) .concat([false, null, undefined]); const salt = Array .from({length:100}, () => String.fromCharCode(32+Math.round(Math.random()*90))) .filter(item => !seed.includes(item)); const overlappingLists = [[...seed,...salt],seed]; const nonOverlappingLists = [salt, seed]; const matchingLists = [seed, seed]; const halfEmptyLists1 = [salt, []]; const halfEmptyLists2 = [[],seed]; describe('Check Solution', function(){ it('Should pass for overlapping arrays', function(){ Test.expect(missing(...overlappingLists), seed); }); it('Should pass for non-overlapping arrays', function(){ Test.expect(missing(...nonOverlappingLists), seed); }); it('Should pass for matching arrays', function(){ Test.expect(missing(...matchingLists), []); }); it('Should pass against empty arrays', function(){ Test.expect(missing(...halfEmptyLists1), []); }); it('Should pass for empty arrays', function(){ Test.expect(missing(...halfEmptyLists2), seed); }); });# TODO: replace with your own tests (TDD). An example to get you started is included below.- const seed = Array
- .from({length:10}, () => String.fromCharCode(32+Math.round(Math.random()*90)))
- .concat([false, null, undefined]);
- const salt = Array
- .from({length:100}, () => String.fromCharCode(32+Math.round(Math.random()*90)))
- .filter(item => !seed.includes(item));
# run the solution and store its result# output = run_shell args: ['my_arg']- const overlappingLists = [[...seed,...salt],seed];
- const nonOverlappingLists = [salt, seed];
- const matchingLists = [seed, seed];
- const halfEmptyLists1 = [salt, []];
- const halfEmptyLists2 = [[],seed];
- describe('Check Solution', function(){
- it('Should pass for overlapping arrays', function(){
- Test.expect(missing(...overlappingLists), seed);
- });
- it('Should pass for non-overlapping arrays', function(){
- Test.expect(missing(...nonOverlappingLists), seed);
- });
- it('Should pass for matching arrays', function(){
- Test.expect(missing(...matchingLists), []);
- });
- it('Should pass against empty arrays', function(){
- Test.expect(missing(...halfEmptyLists1), []);
- });
- it('Should pass for empty arrays', function(){
- Test.expect(missing(...halfEmptyLists2), seed);
- });
- });
# describe "Solution" do# it "should return the argument passed in" do# expect(output).to include('my_arg')# end# end
def maximum_product_of_three(a): a.sort() return max(a[0]*a[1]*a[-1], a[-3]*a[-2]*a[-1])import mathfrom functools import reducedef get_product(numbers):return reduce(lambda a,b:a*b,numbers)def get_negative_products(sorted_asc_negative_numbers):buffer = sorted_asc_negative_numbers.copy()negative_products = []max_negative_numbers_to_take = len(buffer)-len(buffer)%2while max_negative_numbers_to_take>0:negative_products.append(get_product(buffer[:2]))buffer = buffer[2:]max_negative_numbers_to_take-=2return negative_productsdef get_max_number_of_negative_factor_to_take(neg_count,pos_count,take_count):max_negative_numbers_to_take = min(take_count-take_count%2,neg_count-neg_count%2)while take_count-max_negative_numbers_to_take > pos_count and max_negative_numbers_to_take>0:max_negative_numbers_to_take-=2return max_negative_numbers_to_takedef largest_product(numbers_to_multiply,n=3):# sort and filter listsorted_absolutes = sorted(numbers_to_multiply, key = lambda a: -math.fabs(a))sorted_negative = list(filter(lambda a: a<0, sorted_absolutes))sorted_positive = list(filter(lambda a: a>=0, sorted_absolutes))max_negative_numbers_to_take = get_max_number_of_negative_factor_to_take(len(sorted_negative),len(sorted_positive),n)negative_products = get_negative_products(sorted_negative[0:max_negative_numbers_to_take])product_index = 0product_result = 1while product_index<n-1:if len(negative_products)>0:if negative_products[0]>sorted_positive[0]:product_result *= negative_products.pop(0)product_index += 2else:product_result *= sorted_positive.pop(0)product_index +=1else:product_result *= sorted_positive.pop(0)product_index +=1if product_index<n:product_result *= sorted_positive.pop(0)return product_resultdef maximum_product_of_three(numbers):return largest_product(numbers)- def maximum_product_of_three(a):
- a.sort()
- return max(a[0]*a[1]*a[-1], a[-3]*a[-2]*a[-1])
test.assert_equals(maximum_product_of_three([2, -4, 8, -4]), -4 * -4 * 8) test.assert_equals(maximum_product_of_three([4, 3, 5, 2]), 3 * 4 * 5) test.assert_equals(maximum_product_of_three([3, 9, 13]), 3 * 9 * 13) test.assert_equals(maximum_product_of_three([11, -2, -7, 8, 2]), 2 * 8 * 11) test.assert_equals(maximum_product_of_three([-4, -2, -9, -3, -5]), -2 * -3 * -4) test.assert_equals(maximum_product_of_three([-4, -2, -9, 1, -3, -5]), -5 * -9 * 1) test.assert_equals(maximum_product_of_three([-4, -2, -9, 0, -3, -5]), 0)# TODO: Replace examples and use TDD development by writing your own tests# These are some of the methods available:# test.expect(boolean, [optional] message)test.assert_equals(maximum_product_of_three([-4,-4,2,8]), 128)# test.assert_not_equals(actual, expected, [optional] message)# You can use Test.describe and Test.it to write BDD style test groupings- test.assert_equals(maximum_product_of_three([2, -4, 8, -4]), -4 * -4 * 8)
- test.assert_equals(maximum_product_of_three([4, 3, 5, 2]), 3 * 4 * 5)
- test.assert_equals(maximum_product_of_three([3, 9, 13]), 3 * 9 * 13)
- test.assert_equals(maximum_product_of_three([11, -2, -7, 8, 2]), 2 * 8 * 11)
- test.assert_equals(maximum_product_of_three([-4, -2, -9, -3, -5]), -2 * -3 * -4)
- test.assert_equals(maximum_product_of_three([-4, -2, -9, 1, -3, -5]), -5 * -9 * 1)
- test.assert_equals(maximum_product_of_three([-4, -2, -9, 0, -3, -5]), 0)
interleave using Equations.
From Coq Require Import Lists.List omega.Omega. Import ListNotations. From Equations Require Import Equations. Equations interleave {A} (l1 l2 : list A) : list A by wf (length (l1 ++ l2)) lt := interleave [] l2 := l2; interleave (x :: xs) l2 := x :: interleave l2 xs. Next Obligation. rewrite !app_length; omega. Qed. Example test_interleave1: interleave [1;2;3] [4;5;6] = [1;4;2;5;3;6]. Proof. reflexivity. Qed. Example test_interleave2: interleave [1] [4;5;6] = [1;4;5;6]. Proof. reflexivity. Qed. Example test_interleave3: interleave [1;2;3] [4] = [1;4;2;3]. Proof. reflexivity. Qed. Example test_interleave4: interleave [] [20;30] = [20;30]. Proof. reflexivity. Qed.- From Coq Require Import Lists.List omega.Omega.
- Import ListNotations.
Fail Fixpoint interleave {A} (l1 l2 : list A) : list A :=match l1 with| [] => l2| x :: xs => x :: interleave l2 xsend.- From Equations Require Import Equations.
Require Import Recdef.Fail Function interleave {A} (l1 l2 : list A) {measure length (l1 ++ l2)} : list A :=match l1 with| [] => l2| x :: xs => x :: interleave l2 xsend.From Coq Require Import Program.Wf.Program Fixpoint interleave {A} (l1 l2 : list A) {measure (length (l1 ++ l2))} : list A :=match l1 with| [] => l2| x :: xs => x :: interleave l2 xsend.Fail Compute (interleave [1;2;3] [4;5;6]).Next Obligation.simpl.repeat rewrite app_length.omega.Qed.Compute (interleave [1;2;3] [4;5;6]).- Equations interleave {A} (l1 l2 : list A) : list A by wf (length (l1 ++ l2)) lt :=
- interleave [] l2 := l2;
- interleave (x :: xs) l2 := x :: interleave l2 xs.
- Next Obligation. rewrite !app_length; omega. Qed.
- Example test_interleave1:
- interleave [1;2;3] [4;5;6] = [1;4;2;5;3;6].
- Proof. reflexivity. Qed.
- Example test_interleave2:
- interleave [1] [4;5;6] = [1;4;5;6].
- Proof. reflexivity. Qed.
- Example test_interleave3:
- interleave [1;2;3] [4] = [1;4;2;3].
- Proof. reflexivity. Qed.
- Example test_interleave4:
- interleave [] [20;30] = [20;30].
- Proof. reflexivity. Qed.