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.
You can eliminate the need for the second fact function by providing a default for the accumulator.
tailrec fun fact(n: Int, accumulator: Int = 1): Int = if (n == 0) accumulator else fact(n - 1, n * accumulator)
tailrec fun fact(n: Int, accumulator: Int): Int = if (n == 0) accumulator else fact(n - 1, n * accumulator)fun fact(n: Int): Int = fact(n, 1)- tailrec fun fact(n: Int, accumulator: Int = 1): Int = if (n == 0) accumulator else fact(n - 1, n * accumulator)
#import combinators.lc B = \ f g x . f (g x) BB = \ f g x y . f (g x y) C = \ f x y . f y x I = \ x . x K = \ x _ . x KI = \ _ x . x S = \ f g x . f x (g x) T = \ x f . f x V = \ x y f . f x y W = \ f x . f x x Y = \ f . f (Y f) #import church-boolean.lc True = K False = KI and = W C #import church-number.lc succ = S B is-zero = V (K False) True add = \ m n . \ f x . n f (m f x) sub = #inline scott-stream.lc T V \ cons . T (T K) \ head . T (T KI) \ tail . T (Y (S cons)) \ repeat . # factor out go T (S (C cons) (B succ head)) \ go . \ m n . head (n tail (m go (repeat 0))) le = BB is-zero sub eq = \ m n . and (le m n) (le n m) #import scott-pair.lc Pair = V fst = T K #import state-monad.lc return = Pair bind = C fmap = \ fn ma . bind ma \ a . return (fn a) lift2 = \ fn ma mb . bind ma \ a . bind mb \ b . return (fn a b) get = W Pair put = B K (Pair ()) evalState = B fst modify = \ fn . bind get (B put fn) gets = \ fn . bind get (B return fn) #import scott-list.lc nil = K cons = BB K V foldr = \ fn z xxs . xxs z \ x xs . fn x (foldr fn z xs) filterM = \ p . foldr ( \ x . lift2 (V (cons x) I) (p x) ) (return nil) #import scott-int-int-map.lc Empty = \ empty _branch . empty Branch = \ i x l r . \ _empty branch . branch i x l r # index :: Map Number Number -> Number -> Number | () index = \ bst i . bst () \ j x l r . eq i j x (le i j (index l i) # else (index r i) ) # insert-with : (Number -> Number -> Number) -> Number -> Number -> Map Number Number -> Map Number Number # (new value -> old value -> newer value) -> key -> value -> (map -> map) insert-with = \ fn i x bst . bst (Branch i x Empty Empty) \ j y l r . eq i j (Branch i (fn x y) l r) (le i j (Branch j y (insert-with fn i x l) r) # else (Branch j y l (insert-with fn i x r)) ) # deleteNth :: List Number -> Number -> List Number delete-nth = \ xs n . T ( \ x . bind (modify (insert-with add x 1)) \ _ . fmap (C le n) (gets (C index x)) ) \ go . evalState (filterM go xs) Empty
- #import combinators.lc
- B = \ f g x . f (g x)
- BB = \ f g x y . f (g x y)
- C = \ f x y . f y x
- I = \ x . x
- K = \ x _ . x
- KI = \ _ x . x
- S = \ f g x . f x (g x)
- T = \ x f . f x
- V = \ x y f . f x y
- W = \ f x . f x x
- Y = \ f . f (Y f)
- #import church-boolean.lc
True = K- True = K
- False = KI
not = C- and = W C
#import scott-pair.lcPair = Vfst = T K- #import church-number.lc
- succ = S B
- is-zero = V (K False) True
- add = \ m n . \ f x . n f (m f x)
- sub = #inline scott-stream.lc
- T V \ cons .
- T (T K) \ head .
- T (T KI) \ tail .
- T (Y (S cons)) \ repeat .
- # factor out go
- T (S (C cons) (B succ head)) \ go .
- \ m n . head (n tail (m go (repeat 0)))
- le = BB is-zero sub
- eq = \ m n . and (le m n) (le n m)
#import scott-list.lcnil = Kcons = BB K Vfoldr = \ fn z xxs . xxs z \ x xs . fn x (foldr fn z xs)foldl = \ fn z xxs . xxs z \ x xs . foldl fn (fn z x) xslength = foldr (K succ) 0reverse = foldl (C cons) nilfilter = \ p . foldr ( \ x z . p x (cons x z) z ) nil#import scott-assoc-list.lc # TODO: replace with scott-map for performanceempty = nil# index = lookup : assocList i x -> i -> x | ()index = \ assocs j . assocs () \ assoc xs . assoc \ i x . eq i j x (index xs j)insert-with = \ fn j y assocs . assocs (cons (Pair j y) nil) \ assoc xs . assoc \ i x . eq i j (cons (Pair i (fn x y)) xs) (cons assoc (insert-with fn j y xs))# -- State --#import scott-state-monad.lc# State s a = State { runState :: s -> (,) a s }# State = (,) a # forget the type parameters, the wrapper and the unwrapper- #import scott-pair.lc
- Pair = V
- fst = T K
# return : a -> State s a# return = \ a . \ s . Pair a s- #import state-monad.lc
- return = Pair
# bind : State s a -> (a -> State s b) -> State s b# bind = \ ma fn . \ s . let (a,s') = ma s in fn a s'# bind = \ ma fn . \ s . ma s \ a s' . fn a s'# bind = \ ma fn s . ma s fn- bind = C
# get :: State s s# get = \ s . Pair s s- fmap = \ fn ma . bind ma \ a . return (fn a)
- lift2 = \ fn ma mb . bind ma \ a . bind mb \ b . return (fn a b)
- get = W Pair
# put :: s -> State s ()# put s = \ _ . Pair () s- put = B K (Pair ())
# -- helpers --# fmap :: (Monad m) => (a -> b) -> m a -> m b# liftM fn ma = do a <- ma ; return (fn a)fmap = \ fn ma .bind ma \ a .return (fn a)# (<*>) :: (Monad m) => m (a -> b) -> m a -> m b# ap mfn ma = do fn <- mfn ; a <- ma ; return (fn a)ap = \ mfn ma .bind mfn \ fn .bind ma \ a .return (fn a)# liftM2 fn x y = fn <$> x <*> ylift2 = \ fn ma mb . ap (fmap fn ma) mb# join :: (Monad m) => m (m a) -> m a# join mma = mma >>= idjoin = \ mma . bind mma I# modify :: (s -> s) -> State s ()# modify = put . fn =<< get- evalState = B fst
- modify = \ fn . bind get (B put fn)
# gets :: (s -> t) -> State s t# gets = return . fn =<< get- gets = \ fn . bind get (B return fn)
# runState : State s a -> s -> (a,s)# runState = I # there are no wrappers# evalState :: State s a -> s -> a# evalState ma s = fst (ma s)evalState = B fst# filterM :: (Applicative m) => (a -> m Bool) -> [a] -> m [a]# filterM p = foldr (\ x -> liftA2 (\ flg -> if flg then (x:) else id) (p x)) (pure [])- #import scott-list.lc
- nil = K
- cons = BB K V
- foldr = \ fn z xxs . xxs z \ x xs . fn x (foldr fn z xs)
- filterM = \ p . foldr ( \ x . lift2 (V (cons x) I) (p x) ) (return nil)
# -- solution --# deleteNth :: [Int] -> Int -> [Int]# deleteNth xs n = evalState (filterM go xs) empty where# go :: Int -> State (IntMap Int) Bool# go x = do# modify $ insertWith (+) x 1# (<= n) <$> gets (! x)- #import scott-int-int-map.lc
- Empty = \ empty _branch . empty
- Branch = \ i x l r . \ _empty branch . branch i x l r
- # index :: Map Number Number -> Number -> Number | ()
- index = \ bst i . bst () \ j x l r .
- eq i j
- x
- (le i j
- (index l i)
- # else
- (index r i)
- )
- # insert-with : (Number -> Number -> Number) -> Number -> Number -> Map Number Number -> Map Number Number
- # (new value -> old value -> newer value) -> key -> value -> (map -> map)
- insert-with = \ fn i x bst . bst (Branch i x Empty Empty) \ j y l r .
- eq i j
- (Branch i (fn x y) l r)
- (le i j
- (Branch j y (insert-with fn i x l) r)
- # else
- (Branch j y l (insert-with fn i x r))
- )
- # deleteNth :: List Number -> Number -> List Number
- delete-nth = \ xs n .
- T ( \ x .
- bind (modify (insert-with add x 1)) \ _ .
- fmap (C le n) (gets (C index x))
- ) \ go .
evalState (filterM go xs) empty- evalState (filterM go xs) Empty
def find_first_sub_string(text: str, sub: str): return index if ~(index:= text.find(sub)) else None
def find_first_sub_string(text: str, sub: str):index = text.find(sub)return index if index != -1 else None- def find_first_sub_string(text: str,
- sub: str):
- return index if ~(index:= text.find(sub)) else None
fun List<Int>.remove(vararg nums: Int) = filter { !nums.contains(it) }
def remove(integers, values):return list(filter(lambda x: x not in values,integers))- fun List<Int>.remove(vararg nums: Int) = filter { !nums.contains(it) }
import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test class KataTest { @Test fun sample() { assertEquals(listOf(2, 2, 4), listOf(1, 1, 2, 3, 1, 2, 3, 4).remove(1, 3)) assertEquals(listOf(5, 6, 7, 8), listOf(1, 1, 2, 3, 1, 2, 3, 4, 4, 3, 5, 6, 7, 2, 8).remove(1, 3, 4, 2)) assertEquals(listOf(8, 7, 6, 5, 1), listOf(8, 2, 7, 2, 3, 4, 6, 5, 4, 4, 1, 2, 3).remove(2, 4, 3)) } }
@test.describe("Basic Test Cases")def basic_test_cases():test.assert_equals(remove([], []), [])test.assert_equals(remove([1, 1, 3, 5, 7, 7, 7, 9, 10, 10], [1, 7, 9]), [3, 5, 10, 10])test.assert_equals(remove([1, 2, 3, 4, 5], [2, 4]), [1, 3, 5])- import org.junit.jupiter.api.Assertions.*
- import org.junit.jupiter.api.Test
- class KataTest {
- @Test
- fun sample() {
- assertEquals(listOf(2, 2, 4), listOf(1, 1, 2, 3, 1, 2, 3, 4).remove(1, 3))
- assertEquals(listOf(5, 6, 7, 8), listOf(1, 1, 2, 3, 1, 2, 3, 4, 4, 3, 5, 6, 7, 2, 8).remove(1, 3, 4, 2))
- assertEquals(listOf(8, 7, 6, 5, 1), listOf(8, 2, 7, 2, 3, 4, 6, 5, 4, 4, 1, 2, 3).remove(2, 4, 3))
- }
- }