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.
public static class Kata
{
public static int Add(this int a, int b) => a + b;
}
namespace Solution
{
using NUnit.Framework;
using System;
[TestFixture]
public class SolutionTest
{
[Test]
public void MyTest()
{
Assert.AreEqual(4, 1.Add(3));
Assert.AreEqual(4, 2.Add(2));
}
}
}
let (|Even|Odd|) n = if n % 2 = 0 then Even else Odd
let testNum n =
match n with
| Even -> printfn "%i is even" n
| Odd -> printfn "%i is odd" n
testNum 1
testNum 2
testNum 3
testNum 4
testNum 5
let rec quicksort list =
match list with
| [] -> []
| first::rest ->
let smaller,larger = List.partition ((>=) first) rest
List.concat [quicksort smaller; [first]; quicksort larger]
printfn "%A" (quicksort [3;1;5;4;2])
arr2bin=(arr)->
if arr.filter( (n)-> !(n%1==0) ).length
return '0'
sum = arr.map((x)-> if typeof x =="number" then x else 0).reduce((x,y)->(x+y))
return sum.toString(2);
Test.expect(arr2bin([1,2,3]), "It works")
let (|MultOf3|_|) i = if i % 3 = 0 then Some MultOf3 else None
let (|MultOf5|_|) i = if i % 5 = 0 then Some MultOf5 else None
let fizzBuzz i =
match i with
| MultOf3 & MultOf5 -> printfn "FizzBuzz"
| MultOf3 -> printfn "Fizz"
| MultOf5 -> printfn "Buzz"
| _ -> printfn "%i" i
fizzBuzz 3
fizzBuzz 4
fizzBuzz 5
fizzBuzz 15
let stringToCharList (s : string) = s.ToCharArray() |> List.ofArray
let charListToString (list : char list) = list |> List.map(fun c -> c.ToString()) |> List.reduce(fun s str -> s + str)
let phraseToWords (phrase : string) = phrase.Split(' ') |> List.ofArray
let wordsToPhrase (words : string list) = words |> List.reduce(fun s str -> s + " " + str)
let translateWord (word : char list) =
match word with
| 'a' :: rest
| 'e' :: rest
| 'i' :: rest
| 'o' :: rest
| 'u' :: rest
| 'x' :: 'r' :: rest
| 'y' :: 't' :: rest -> word @ ['a'; 'y']
| 'c' :: 'h' :: rest -> rest @ ['c'; 'h'; 'a'; 'y']
| 'q' :: 'u' :: rest -> rest @ ['q'; 'u'; 'a'; 'y']
| c :: 'q' :: 'u' :: rest -> rest @ [c] @ ['q'; 'u'; 'a'; 'y']
| 't' :: 'h' :: 'r' :: rest -> rest @ ['t'; 'h'; 'r'; 'a'; 'y']
| 't' :: 'h' :: rest -> rest @ ['t'; 'h'; 'a'; 'y']
| 's' :: 'c' :: 'h' :: rest -> rest @ ['s'; 'c'; 'h'; 'a'; 'y']
| c :: rest -> rest @ [c] @ ['a'; 'y']
| _ -> []
let translateWords (words : string list) = words |> List.map(fun word -> word |> stringToCharList |> translateWord |> charListToString)
let translate (phrase : string) = phrase |> phraseToWords |> translateWords |> wordsToPhrase
printfn "%s" (translate "hello world")
Haskell is lazy, so we could get infinite sequence naturally.
like this.
module InfiniteSeq where
import Data.List
ones = repeat 1
nats = [0..]
merge = concat . transpose
merge2 x y = merge [x, y]
ints = 0: merge2 [1..] [(-1),(-2)..]
module Codewars.InfiniteSeq.Test where
import InfiniteSeq
import Test.Hspec
import Test.QuickCheck
import Test.Hspec.QuickCheck
main = hspec $ do
describe "test infinite" $ do
it "test ones" $ do
take 3 ones `shouldBe` [1,1,1]
it "test naturals" $ do
take 11 InfiniteSeq.nats `shouldBe` [0..10]
it "test ints" $ do
10 `elem` ints `shouldBe` True
(-10) `elem` ints `shouldBe` True
write one compare function.
- first compare with string's length
- when string have same length, then compare string with lex order.
module CmpStr where
import Data.Function
import Data.Monoid
cmpStr :: String -> String -> Ordering
cmpStr = (compare `on` length) `mappend` compare
module CmpStr.Test where
import CmpStr
import Test.Hspec
import Test.QuickCheck
main = hspec $ do
describe "test for cmpstr" $ do
it "test cmpstr" $ do
cmpStr "abc" "defz" `shouldBe` LT
cmpStr "abcd" "def" `shouldBe` GT
cmpStr "abc" "abc" `shouldBe` EQ
cmpStr "abc" "def" `shouldBe` LT
There seems to be an error with looking at the top of a stack, but it doesn't throw. It just kills execution. What's going on here?
#include <stack>
bool method()
{
std::stack<int> my_stack;
//my_stack.push(1);
try {
if(my_stack.top())
{
}
}
catch(...) {
std::cout << "An Exception Occurred" << std::endl;
}
return true;
}
Describe(check_the_stack)
{
It(should_do_something)
{
Assert::That(method(), Equals(true));
}
};