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.
math.sqrt(n) = n**.5
although that may lead unreadable code.
for python 3 replace long(...) with int(...)
const duplicates = a => a.reduce((r, v, i, l) => !r.includes(v) && l.indexOf(v) !== i ? [...r, v] : r, []);
function duplicates(arr) {var out = [];for(var x=0;x<arr.length-1;x++){var ch = arr[x];for(var y=x+1;y<arr.length;y++){var comp = arr[y];if (comp === ch && out.indexOf(comp) === -1){out.push(comp);break;}}}out.sort();return out;}- const duplicates = a => a.reduce((r, v, i, l) => !r.includes(v) && l.indexOf(v) !== i ? [...r, v] : r, []);
Comparing lists using the length
function is problematical because it requires counting every item in both lists. However, we only need to count up until the length of the shortest list + 1 to know which one is shorter. This can make a big difference in performance if one list is much longer than the other -- and make the difference between termination and non-termination if one list is infinite.
My change fixes this problem by avoiding the use of the length
function. I've also changed the tests to make sure the solution works when one list is infinite.
module CmpStr where import Data.Function import Data.Monoid cmpStr :: String -> String -> Ordering cmpStr = (compare `on` map (const ())) `mappend` compare
- module CmpStr where
- import Data.Function
- import Data.Monoid
- cmpStr :: String -> String -> Ordering
cmpStr = (compare `on` length) `mappend` compare- cmpStr = (compare `on` map (const ())) `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 cmpStr "zzz" (repeat 'a') `shouldBe` LT
- 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
- cmpStr "zzz" (repeat 'a') `shouldBe` LT
def myMap(mine): l = [i+1 for i in mine] return l
def sayHello(say):say.append("bulbul")return say- def myMap(mine):
- l = [i+1 for i in mine]
- return l
# 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 mine = [1, 2, 3, 4, 5, 6, 7, 8, 9] Test.assert_equals(myMap(mine), [2, 3, 4, 5, 6, 7, 8, 9, 10])
- # 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
say = ["Hi!", "Oh My!", "OMG", "Hello!"]Test.assert_equals(sayHello(say), ["Hi!", "Oh My!", "OMG", "Hello!","bulbul"])- mine = [1, 2, 3, 4, 5, 6, 7, 8, 9]
- Test.assert_equals(myMap(mine), [2, 3, 4, 5, 6, 7, 8, 9, 10])