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.
let rec sumMult i k n = if i + k < n then i + sumMult (i + k) k n else i
let sumOfMultiples list n = list |> List.map(fun x -> sumMult 0 x n) |> List.sum
printfn "%A" (sumOfMultiples [1; 2; 3] 10)
let rec sumMult i k n = if i + k < n then i + sumMult (i + k) k n else i
let sumOfMultiples list n = list |> List.map(fun x -> sumMult 0 x n) |> List.sum
let v = sumOfMultiples [7; 13; 17] 20
printfn "%A" v
Contains random dart tests
class Person {
String firstName;
String lastName;
Person(this.firstName,this.lastName);
}
// Create your own tests here using the Test package (https://github.com/dart-lang/test)
// Here is some boilerplate:
test('Should be able to create a Person object', () {
expect(new Person('Bill', 'Smith'), new isInstanceOf<Person>());
});
test('Person object has expected name', () {
var p = new Person('Bill', 'Smith');
expect(p.firstName, equals('Bill'));
expect(p.lastName, equals('Smith'));
});
http://www.willamette.edu/~fruehr/haskell/seuss.html
A parser for a thing
Is a function from a string
To a list of pairs
Of things and strings!
This monadic parser is missing many basic functions and several important typeclass instances.
{-# LANGUAGE DeriveFunctor, TupleSections #-}
module MonadicParsing where
newtype Parser a = Parser { runParser :: String -> [(a, String)] }
deriving Functor
instance Monad Parser where
return a = Parser $ return . (a,)
Parser p >>= f = Parser $ \s -> concatMap (uncurry (runParser.f)) $ p s
import Data.Char
import Data.List
import Test.Hspec
import MonadicParsing (Parser (..))
main :: IO ()
main = hspec spec
takeParser :: Int -> Parser String
takeParser l = Parser $ \s -> [(take l s, drop l s)]
digitParser :: Parser Int
digitParser = Parser $ \s -> [ (digitToInt a, drop 1 s) | a <- take 1 s, isDigit a ]
repeatParser :: Show a => a -> Parser a
repeatParser a = Parser $ \s -> [(a, drop l s) | t `isPrefixOf` s]
where
t = show a
l = length t
spec :: Spec
spec = do
describe "monad instance" $ do
it "left identity" $ runParser (return 3 >>= takeParser) "hello"
`shouldBe` runParser (takeParser 3) "hello"
it "right identity" $ runParser (takeParser 9 >>= return) "world"
`shouldBe` runParser (takeParser 9) "world"
it "associativity" $ runParser ((digitParser >>= repeatParser) >>= takeParser) "99 luftballons"
`shouldBe` runParser (digitParser >>= (\x -> repeatParser x >>= takeParser)) "99 luftballons"
let addOne = fun x -> x + 1
let value = addOne <| 1 |> addOne
printfn "%i" value
let rec print list =
match list with
| [] -> ()
| head::rest -> head |> printfn "%O"; print(rest)
print [1; 5; 7]
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")