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.
Here's the code that I'm using to list all files in a given directory. The question is, is there any other way to do this?
import glob
print(glob.glob('directorypath'))# Replace 'directorypath' with path to directory
# 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
from the rowanblush solution
using Ordering monoid instance we can change the bias on EQ for all higher order accepting (a -> a -> Ordering)
module LeftBias where
import Data.Monoid
leftBias g = g . (fmap . fmap) (`mappend` GT)
import Data.List
import Data.Ord
import Test.Hspec
import LeftBias
main = hspec $ do
describe "leftBias with maximumBy" $ do
it "maximumBy is right biased" $
maximumBy (comparing length) ["ciao","wave"] `shouldBe` "wave"
it "leftBias maximumBy is left biased" $
leftBias maximumBy (comparing length) ["ciao","wave"] `shouldBe` "ciao"
Hello world in Kotlin.
fun main(args: Array<String>) {
println("Hello from Kotlin")
}
In Kotlin data classes is classes which do nothing but only hold data.
The compiler automatically derives the following members from all properties declared in the primary constructor:
- equals()/hashCode() pair,
- toString() of the form "User(name=John, age=42)",
- componentN() functions corresponding to the properties in their order of declaration,
- copy() function (see below).
data class User(val id: Long, var email: String, var name: String)
fun main(args: Array<String>) {
var user = User(1, "random@email.com", "randomName")
// toString
println(user)
// equals
println(user.equals(User(1, "random@email.com", "randomName")))
// ComponentN
println("user name is ${user.component3()}")
// copy
var newUser = user.copy(name="newName")
println(newUser)
}
Write a program that removes the element at the nth index in the provided array, and returns the new array.
If the number provided is not an index in the array, return the original array.
For Example:
remove([1, 2, 3], 2) => [1, 2]
remove(["dog", "cat", "bat", "parrot", "monkey"], 4) => ["dog", "cat", "bat", "parrot"]
function remove (arr, n) {
if (n < 0 || n >= arr.length) return arr;
arr.splice(n, 1);
return arr;
}
// TODO: Replace examples and use TDD development by writing your own tests
// These are some CW specific test methods available:
// Test.expect(boolean, [optional] message)
// Test.assertEquals(actual, expected, [optional] message)
// Test.assertSimilar(actual, expected, [optional] message)
// Test.assertNotEquals(actual, expected, [optional] message)
// NodeJS assert is also automatically required for you.
// assert(true)
// assert.strictEqual({a: 1}, {a: 1})
// assert.deepEqual({a: [{b: 1}]}, {a: [{b: 1}]})
// You can also use Chai (http://chaijs.com/) by requiring it yourself
// var expect = require("chai").expect;
// var assert = require("chai").assert;
// require("chai").should();
describe("Solution", function(){
it("should remove the correct element", function(){
Test.assertSimilar(remove([1, 2, 3], 2), [1, 2], "Wrong! Try again.");
Test.assertSimilar(remove([1, 2, 3, 4, 5, 6, 2, 1, 5, 3], 8), [1, 2, 3, 4, 5, 6, 2, 1, 3], "Wrong! Try again.");
Test.assertSimilar(remove(["1,2,3,4,5", "test", 7, {obj: "obj"}, [8,2,5]], 3), ["1,2,3,4,5", "test", 7, [8,2,5]], "Wrong! Try again.");
Test.assertSimilar(remove(["dog", "cat", "bat", "parrot", "monkey"], 4), ["dog", "cat", "bat", "parrot"], "Wrong! Try again.");
});
it("should return original array if index is out of range", function(){
Test.assertSimilar(remove([1, 2, 3], 20), [1, 2, 3], "Wrong! Try again.");
Test.assertSimilar(remove([1, 2, 3, 4, 5, 6, 2, 1, 5, 3], 17), [1, 2, 3, 4, 5, 6, 2, 1, 5, 3], "Wrong! Try again.");
Test.assertSimilar(remove(["1,2,3,4,5", "test", 7, {obj: "obj"}, [8,2,5]], -19), ["1,2,3,4,5", "test", 7, {obj: "obj"}, [8,2,5]], "Wrong! Try again.");
Test.assertSimilar(remove(["dog", "cat", "bat", "parrot", "monkey"], -1), ["dog", "cat", "bat", "parrot", "monkey"], "Wrong! Try again.");
});
});
Finds top 7 most frequent words in the book.
(ns most-frequent-words.core)
(defn most-frequent-words[number-of-words, book-url]
"Finds top 7 most frequent words in the book"
(->>
(slurp book-url)
(re-seq #"\w+")
(frequencies)
(sort-by val >)
(take number-of-words)))
(ns most-frequent-words.test
(:require [clojure.test :refer :all]
[most-frequent-words.core :refer [most-frequent-words]]))
(deftest most-frequent-words-test
;; ROMEO AND JULIET
(def romeo-and-juliet-book-url "http://www.textfiles.com/etext/AUTHORS/SHAKESPEARE/shakespeare-romeo-48.txt")
;; OTHELLO
(def othello-book-url "http://www.textfiles.com/etext/AUTHORS/SHAKESPEARE/shakespeare-othello-47.txt")
;; THE WINTER'S TALE
(def the-winter-s-tale-book-url "http://www.textfiles.com/etext/AUTHORS/SHAKESPEARE/shakespeare-winters-19.txt")
(is (=
(most-frequent-words 7 romeo-and-juliet-book-url)
[["I" 656] ["the" 614] ["and" 490] ["to" 488] ["a" 411] ["of" 367] ["my" 314]]))
(is (=
(most-frequent-words 7 othello-book-url)
[["I" 892] ["the" 674] ["and" 596] ["to" 509] ["you" 453] ["of" 420] ["a" 397]]))
(is (=
(most-frequent-words 7 the-winter-s-tale-book-url)
[["the" 717] ["I" 713] ["and" 535] ["to" 517] ["of" 428] ["you" 399] ["a" 378]])))
Polymer({
is: "pedal-assist",
properties:{
ppc:{
type:Number,
value:30,
},
gap:{
type:Number,
computed:"getGap(lPedel,rPedel)",
},
cycle:{
type:Number,
value:.5,
},
},
left: function(undefined){
this.lPedel = performance.now()
},
right: function(undefined){
this.rPedel = performance.now()
},
getGap: function(lPedel,rPedel){
var newGap = Math.sqrt((lPedel - rPedel) * (lPedel - rPedel))
var r1 = this.gapOld / this.gap
var r2 = this.gap / newGap
console.log(r1,r2,newGap)
if (r1 < 1.2 && r1 > .8 && r2 < 1.2 && r2 > .8) {
this.runMotor(this.cycle,this.ppc,this.gap)
}
this.gapOld = this.gap
return newGap
},
runMotor: function(cycle,ppc,time){
var n= Math.floor(ppc*cycle)
for (var i=1;i<n;i++) {
setTimeout(function(that){
if (that.black == 0) {
that.set("black", 12)
that.yellow = 0
that.red = -12
} else if (that.yellow == 0) {
that.black = -12
that.yellow = 12
that.red = 0
} else if (that.red == 0) {
that.black = 0
that.yellow = -12
that.red = 12
}
}, (time*cycle)*(i/n),this)
console.log((time*cycle)*(i/n))
}
setTimeout(function(that){
that.black = 0
that.yellow = 0
that.red = 0
}, (time*cycle)+10,this)
},
})
// TODO: Replace examples and use TDD development by writing your own tests
// These are some CW specific test methods available:
// Test.expect(boolean, [optional] message)
// Test.assertEquals(actual, expected, [optional] message)
// Test.assertSimilar(actual, expected, [optional] message)
// Test.assertNotEquals(actual, expected, [optional] message)
// NodeJS assert is also automatically required for you.
// assert(true)
// assert.strictEqual({a: 1}, {a: 1})
// assert.deepEqual({a: [{b: 1}]}, {a: [{b: 1}]})
// You can also use Chai (http://chaijs.com/) by requiring it yourself
// var expect = require("chai").expect;
// var assert = require("chai").assert;
// require("chai").should();
describe("Solution", function(){
it("should test for something", function(){
Test.assertEquals("actual", "expected", "This is just an example of how you can write your own TDD tests");
});
});
public class Primes {
public static boolean isAPrime(int number) {
return true;
}
}
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
public class SolutionTest {
@Test
public void twoShouldBeAPrime() {
int numberToCheck = 2;
boolean expected = true;
boolean actual = Primes.isAPrime(numberToCheck);
assertEquals(expected, actual);
}
}
Raise 2 to the power 10 without using Math.pow or defining your own function.
Make it in one expression.
let x = let rec pow2 n = match n with | 0 -> 1 | _ -> 2 * pow2 (n - 1) in pow2 10
printfn "%i" x
power function
let rec power a n = match n with | 0 -> 1 | _ -> a * power a (n - 1)
printfn "%i" (power 2 4)
printfn "%i" (power 3 3)
printfn "%i" (power 4 2)