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.

Ad
Ad
Arrays
Data Types
Algorithms
Logic
Data
Code
Diff
  • // 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,[])
    • }
Bash
Regular Expressions
Declarative Programming
Advanced Language Features
Programming Paradigms
Fundamentals
Strings
Code
Diff
  • 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));
Code
Diff
  • def maximum_product_of_three(a):
        a.sort()
        return max(a[0]*a[1]*a[-1], a[-3]*a[-2]*a[-1])
    • import math
    • from functools import reduce
    • def 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)%2
    • while max_negative_numbers_to_take>0:
    • negative_products.append(get_product(buffer[:2]))
    • buffer = buffer[2:]
    • max_negative_numbers_to_take-=2
    • return negative_products
    • def 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-=2
    • return max_negative_numbers_to_take
    • def largest_product(numbers_to_multiply,n=3):
    • # sort and filter list
    • sorted_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 = 0
    • product_result = 1
    • while product_index<n-1:
    • if len(negative_products)>0:
    • if negative_products[0]>sorted_positive[0]:
    • product_result *= negative_products.pop(0)
    • product_index += 2
    • else:
    • product_result *= sorted_positive.pop(0)
    • product_index +=1
    • else:
    • product_result *= sorted_positive.pop(0)
    • product_index +=1
    • if product_index<n:
    • product_result *= sorted_positive.pop(0)
    • return product_result
    • def 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])
Code
Diff
  • const compute = Number.bind('', 1);
    • let compute = Number.bind('', 1);
    • const compute = Number.bind('', 1);
Advanced Language Features
Fundamentals
Theorem Proving

interleave using Equations.

Code
Diff
  • 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 xs
    • end.
    • 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 xs
    • end.
    • 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 xs
    • end.
    • 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.