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.
Here's an interesting verification challenge - verify the following efficient implementation of a solution to the longest common subsequence problem (adapted from @JohanWiltink's Haskell solution to Longest Common Subsequence (Performance version)):
(* Adapted from @JohanWiltink's solution to Longest Common
Subsequence (Performance Version) *)
Fixpoint elem_index {A : Type}
(eq_dec : forall x y : A, {x = y} + {x <> y})
(n : A) (l : list A) : option nat :=
match l with
| [] => None
| x :: xs =>
if eq_dec n x
then Some O
else
match elem_index eq_dec n xs with
| Some idx => Some (S idx)
| None => None
end
end.
Fixpoint lcs_aux {A : Type} (gas : nat)
(eq_dec : forall x y : A, {x = y} + {x <> y})
(l l' : list A) : list A :=
match gas with
| O => []
| S gas' =>
match l with
| [] => []
| x :: xs =>
match l' with
| [] => []
| y :: ys =>
if eq_dec x y
then x :: lcs_aux gas' eq_dec xs ys
else
let
lcs0 := match elem_index eq_dec x ys with
| Some i => x :: lcs_aux gas' eq_dec
xs (skipn (S i) ys)
| None => []
end in
let
lcs1 := match elem_index eq_dec y xs with
| Some j => y :: lcs_aux gas' eq_dec
(skipn (S j) xs) ys
| None => []
end in
let lcs2 := lcs_aux gas' eq_dec xs ys in
let lcs0_length := length lcs0 in
let lcs1_length := length lcs1 in
let lcs2_length := length lcs2 in
if le_dec lcs0_length lcs1_length
then if le_dec lcs1_length lcs2_length
then lcs2
else lcs1
else if le_dec lcs0_length lcs2_length
then lcs2
else lcs0
end
end
end.
Definition lcs {A : Type}
(eq_dec : forall x y : A, {x = y} + {x <> y})
(l l' : list A) : list A :=
lcs_aux (length l + length l') eq_dec l l'.
Why a Kumite? Why not a Kata?
Long story short, I haven't been able to figure out how to prove it correct (hence "Open Challenge" in the title of this Kumite) or disprove it (if it turns out to be buggy and fails on some weird obscure edge case that was somehow untested in the original Kata). So if you can prove it correct or find a bug in the implementation before I do and decide not to keep your findings secret, you have two options:
- Spar on this Kumite by forking it and providing a complete (ideally axiom-free, though common axioms such as excluded middle are also acceptable) proof of the (in)correctness of the above implementation, OR
- Convert your complete solution into a Kata so other Codewarriors can try proving it correct/incorrect for themselves. You can take all the credit for coming up with this Kata.
Good luck ;-)
Require Import Preloaded.
Theorem lcs_correct : forall {A} (eq_dec : forall x y : A,
{x = y} + {x <> y}) xs ys zs,
lcs eq_dec xs ys = zs ->
IsLCS zs xs ys.
Proof.
admit.
Admitted.
Require Solution.
Require Import Preloaded.
From CW Require Import Loader.
CWGroup "Solution.lcs_correct".
CWTest "should have the correct type".
CWAssert Solution.lcs_correct : (forall {A} (eq_dec : forall x y : A,
{x = y} + {x <> y}) xs ys zs,
lcs eq_dec xs ys = zs ->
IsLCS zs xs ys).
CWTest "should be closed under the global context".
CWAssert Solution.lcs_correct Assumes.
CWEndGroup.
Create functions thas can sort an array using insertion sort algorithm. Function should return a COPY of sorted array, so the original array wouldn't be mutated
Note: you shouldn't use loops (for/while). Try to complete task in a functional way.
function insertionSort(arr) {
// return sorted array
}
describe("Solution", function() {
it("should test for something", function() {
Test.assertDeepEquals([-1, 0, 1, 2, 3, 5, 6, 9], insertionSort([0, -1, 9, 5, 6, 3, 1, 2]));
Test.assertDeepEquals([], insertionSort([]));
Test.assertDeepEquals([1,2,3], insertionSort([1,2,3]));
Test.assertDeepEquals([0, 0, 1, 1, 1, 9], insertionSort([0, 1, 1, 9, 0, 1]));
Test.assertDeepEquals([4, 100000000, 1000000000000000], insertionSort([1000000000000000, 4, 100000000]));
});
});
Write a script which can find indexes & sum of biggest possible sequence subarray items.
Example:
findBiggestSubArray([1, 2, -3, 2])
should return array like [a, b, c]
Where:
a: maximal sum of sequence
b: start index if sequence
c: last index of sequence
More examples:
findBiggestSubArray([1, 1, 1, 1, 1, 1, -5]) ==> return [6, 0, 5]
findBiggestSubArray([-9,1,3,1,1,-6,0,-9]) ==> [6, 1, 4]
findBiggestSubArray([-9,4,-1,5]) ==> [8, 1, 3]
findBiggestSubArray([-9, 4, 1, 1, -9, 5]) ==> [6, 1, 3]
findBiggestSubArray([-9]) ==> [-9, 0, 0]
findBiggestSubArray([-9,8,-2.5,2,1]) ==> [8.5, 1, 4]
function findBiggestSubArray(arr) {
return []
}
describe("Solution", function() {
it("should test for something", function() {
Test.assertDeepEquals(findBiggestSubArray([1, 1, 1, 1, 1, 1, -5]), [6, 0, 5]);
Test.assertDeepEquals(findBiggestSubArray([-9,1,3,1,1,-6,0,-9]), [6, 1, 4]);
Test.assertDeepEquals(findBiggestSubArray([-9,4,-1,5]), [8, 1, 3]);
Test.assertDeepEquals(findBiggestSubArray([-9, 4, 1, 1, -9, 5]), [6, 1, 3]);
Test.assertDeepEquals(findBiggestSubArray([-9]), [-9, 0, 0]);
Test.assertDeepEquals(findBiggestSubArray([-9,8,-2.5,2,1]), [8.5, 1, 4]);
});
});
This is about several ways to represent finite types (in Agda).
(Stub)
{-# OPTIONS --safe #-}
module Example where
open import Data.List
open import Data.Fin
open import Data.Nat
open import Data.Empty
open import Function.Inverse
open import Function.Injection
open import Data.Product
open import Data.List.Membership.Propositional
open import Data.Unit
open import Data.Sum
open import Preloaded
finiteEquivalent : ∀ {l} (A : Set l) → Finite₁ A ↔ Finite₂ A
finiteEquivalent = {!!}
notInfiniteEquivalent : ∀ {l} (A : Set l) → NotInfinite₁ A ↔ NotInfinite₂ A
notInfiniteEquivalent = {!!}
finiteIsNotInfinite : ∀ {l} (A : Set l) → Finite₁ A → NotInfinite₁ A
finiteIsNotInfinite = {!!}
{-# OPTIONS --safe #-}
module Test where
open import Example
finiteEquivalent' : ∀ {l} (A : Set l) → Finite₁ A ↔ Finite₂ A
finiteEquivalent' = finiteEquivalent
notInfiniteEquivalent' : ∀ {l} (A : Set l) → NotInfinite₁ A ↔ NotInfinite₂ A
notInfiniteEquivalent' = notInfiniteEquivalent
finiteIsNotInfinite' : ∀ {l} (A : Set l) → Finite₁ A → NotInfinite₁ A
finiteIsNotInfinite' = finiteIsNotInfinite
there is an error, fix it
(test kumite only)
function m (a, b) {
a * b
}
Given a positive number N, you have to return if N is odd.
Example:
-> N = 3, return "True"
-> N = 42, return "False"
Good Luck !
def isOdd(n) :
return "False" if n % 2 == 0 else "True"
import random
test.describe("Fixe Tests")
test.assert_equals(isOdd(3), "True")
test.assert_equals(isOdd(42), "False")
test.describe("Random Tests")
for i in range(100) :
N = random.randint(0, 10000)
result = "False" if N % 2 == 0 else "True"
test.assert_equals(isOdd(N), result)
Check if a given Int number have a perfect square.
func isPerfectSquare(_ input: Int) -> Bool {
let inputAsDouble = Double(input)
return inputAsDouble.squareRoot().rounded() == inputAsDouble.squareRoot()
}
import XCTest
// XCTest Spec Example:
// TODO: replace with your own tests (TDD), these are just how-to examples to get you started
class SolutionTest: XCTestCase {
static var allTests = [
("Test Numbers From 0 To 10", testNumbersFrom0To10),
]
func testNumbersFrom0To10() {
XCTAssertEqual(isPerfectSquare(0), true, "0")
XCTAssertEqual(isPerfectSquare(1), true, "1")
XCTAssertEqual(isPerfectSquare(2), false, "2")
XCTAssertEqual(isPerfectSquare(3), false, "3")
XCTAssertEqual(isPerfectSquare(4), true, "4")
XCTAssertEqual(isPerfectSquare(5), false, "5")
XCTAssertEqual(isPerfectSquare(6), false, "6")
XCTAssertEqual(isPerfectSquare(7), false, "7")
XCTAssertEqual(isPerfectSquare(8), false, "8")
XCTAssertEqual(isPerfectSquare(9), true, "9")
XCTAssertEqual(isPerfectSquare(10), false, "10")
}
}
XCTMain([
testCase(SolutionTest.allTests)
])
A list needs to be sorted with its first field in ascending order, if a match is found then the second field should be sorted in descending order.
I found that if the second field is an integer this can be easily done by negating the integer key value.
For example:
key = lambda x: (x.name, - x.age))
The negation does not work on string.
Hence I did the following code to achieve the expected result. I would like to know other ways of sorting a list in different orders.
def revString(string):
'''Using the returned string to reverse the ordering'''
return ''.join([chr(122 - ord(x)%97) for x in string.lower()])
def sortlist(listtosort):
sortedlist = sorted(listtosort, key = lambda x: (x[0], revString(x[1])))
return sortedlist
listtosort = [("abc", "ghi"), ("abc", "ghj"), ("abc", "abc"), ("def", "ghc"), ("ghi", "ghc"), ("ghi", "abc")]
sortedlist = [('abc', 'ghj'), ('abc', 'ghi'), ('abc', 'abc'), ('def', 'ghc'), ('ghi', 'ghc'), ('ghi', 'abc')]
test.assert_equals(sortlist(listtosort), sortedlist)
listtosort = [("abc", "ghi"), ("def", "ghj"), ("abc", "abc"), ("def", "ghc"), ("ghi", "abc"), ("xyz", "abc")]
sortedlist = [('abc', 'ghi'), ('abc', 'abc'), ('def', 'ghj'), ('def', 'ghc'), ('ghi', 'abc'), ('xyz', 'abc')]
test.assert_equals(sortlist(listtosort), sortedlist)
sort
def tickets(l):
return #sdsdsd
test.assert_equals(tickets([25, 25, 50]), "YES")
test.assert_equals(tickets([25, 100]), "NO")
#testing kumite
# 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(actual, expected, [optional] message)
# test.assert_not_equals(actual, expected, [optional] message)
# You can use Test.describe and Test.it to write BDD style test groupings