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.
A few less spaces...
Assumes entry lists are sorted !!
#include <list> auto merge_list(const std::list<int>& a, const std::list<int>& b) { std::list<int> o{a}; for(auto i : b) o.insert(std::lower_bound(o.begin(), o.end(), i), i); return o; }
#include <algorithm>- #include <list>
#include <execution>#include <iterator>- auto merge_list(const std::list<int>& a, const std::list<int>& b) {
std::list<int> o;std::merge(std::execution::seq,a.begin(),a.end(),b.begin(),b.end(),std::back_inserter(o)// std::less is default sort);- std::list<int> o{a};
- for(auto i : b) o.insert(std::lower_bound(o.begin(), o.end(), i), i);
- return o;
- }
- Added 3 more test cases
- Follwing problem description:
Counting from 1 to n, then back to 1 - Wait, why am I doing this?
module NumberPrint where numberprint :: Int -> Integer numberprint n = read . concat $ show <$> [1 .. pred n] <> [n, pred n .. 1]
- module NumberPrint where
- numberprint :: Int -> Integer
numberprint = read . (>>= id) . ((++) <*> (reverse . init)) . (\x -> show <$> [1..x])- numberprint n = read . concat $ show <$> [1 .. pred n] <> [n, pred n .. 1]
module NumberPrintSpec where import Test.Hspec import NumberPrint spec :: Spec spec = do describe "Tests" $ do it "Fixed Tests" $ do numberprint 1 `shouldBe` 1 numberprint 2 `shouldBe` 121 numberprint 10 `shouldBe` 12345678910987654321 numberprint 12 `shouldBe` 1234567891011121110987654321 numberprint 15 `shouldBe` 1234567891011121314151413121110987654321 main = hspec spec
- module NumberPrintSpec where
- import Test.Hspec
- import NumberPrint
- spec :: Spec
- spec = do
- describe "Tests" $ do
- it "Fixed Tests" $ do
- numberprint 1 `shouldBe` 1
- numberprint 2 `shouldBe` 121
- numberprint 10 `shouldBe` 12345678910987654321
- numberprint 12 `shouldBe` 1234567891011121110987654321
- numberprint 15 `shouldBe` 1234567891011121314151413121110987654321
- main = hspec spec
Combinators are useful.
I'd like a safe tail
function though.
EDIT: drop
could be used instead.
<*>
is S
combinator.
- For
A <*> B
, parameter is piped to both A and B - and then, they are applied
- i.e.
A <*> B = \x -> (A x) (B x)
Pattern matching on number is lame, so implemented using a list.
- Pattern
- on each step, 2 is multipled on each element
- 1 is added in between
-
(iterate step initial !!)
could be used to get result of application n times - List monad is great!
- View pattern is unnecessary now.
module Code (powerfulArray) where import Data.List powerfulArray :: Int -> [Int] powerfulArray = (iterate next [] !!) where next l = 1 : (do n <- l; [2 * n, 1])
{-# Language ViewPatterns #-}- module Code (powerfulArray) where
- import Data.List
- powerfulArray :: Int -> [Int]
powerfulArray 0 = []powerfulArray (pred -> n) = arrayN ++ 2^n : arrayNwhere arrayN = powerfulArray n- powerfulArray = (iterate next [] !!) where next l = 1 : (do n <- l; [2 * n, 1])
module TestSpec (spec) where import Code (powerfulArray) import Test.Hspec spec :: Spec spec = do it "is initial cases" $ do powerfulArray 0 `shouldBe` [] powerfulArray 1 `shouldBe` [1] powerfulArray 2 `shouldBe` [1, 2, 1] powerfulArray 3 `shouldBe` [1, 2, 1, 4, 1, 2, 1] powerfulArray 4 `shouldBe` [1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1] powerfulArray 5 `shouldBe` [1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1, 16, 1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1]
- module TestSpec (spec) where
- import Code (powerfulArray)
- import Test.Hspec
- spec :: Spec
- spec = do
it "should test for something" $ do- it "is initial cases" $ do
- powerfulArray 0 `shouldBe` []
- powerfulArray 1 `shouldBe` [1]
- powerfulArray 2 `shouldBe` [1, 2, 1]
- powerfulArray 3 `shouldBe` [1, 2, 1, 4, 1, 2, 1]
- powerfulArray 4 `shouldBe` [1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1]
- powerfulArray 5 `shouldBe` [1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1, 16, 1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1]