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.
Code returns the int that is different from all other ints in an array. Function takes odd size array that contains all the same ints except for 1
int stray(std::vector<int> numbers) {
for(auto n = numbers.begin(); n != numbers.end(); ++n ){
if (*n != numbers[0]) {
if (*n != *(n + 1))
return *n;
else
return numbers[0];
}
}
};
// TODO: Replace examples and use TDD development by writing your own tests
Describe(array)
{
It(should_do_something)
{
Assert::That(stray({0,1,1,1}), Equals(0));
}
};
Sometimes one has a vector with pairs (key, value), where one wants to fold over all the values with the same key.
What is the best way to do that in Rust?
The example uses a vector, but perhaps it would be better with an iterator as argument, to make it more general?
fn reduce<TK, TV, TS, F>(v : Vec<(TK, TV)>,
s : TS,
f : F) -> Vec<(TK, TV)>
where F : Fn(TS, TV) -> TS {
// Code
vec![]
}
// Rust test example:
// TODO: replace with your own tests (TDD), these are just how-to examples.
// See: https://doc.rust-lang.org/book/testing.html
#[test]
fn returns_summariesed_word_count() {
assert_eq!(reduce(vec![("a", 2), ("b", 1), ("a", 1)],
0,
|s, v| s + v), vec![("a", 3), ("b", 1)])
}
Array and looping are in old-love story . Tonight we gonna play the game by separae them . given integer array , we want to sort it without the use of any kind of arrays .
Hint ::
You can write it in one line - Code
def sortinggggggggggg (arr) :
Soreteddddd = sorted (arr)
return Soreteddddd
sortinggggggggggg ([2,0,25,3])
# 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
Kumite Experiment!
public class HelloWorld
{
public static int Execute()
{
System.out.println("My first Kumite");
return 1;
}
}
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
// TODO: Replace examples and use TDD development by writing your own tests
public class SolutionTest {
@Test
public void testSomething() {
// assertEquals("expected", "actual");
assertEquals(1,HelloWorld.Execute());
}
}
given we are anonymous
then should say "Hello World!"
given we are "McFly"
then should say "Hello McFly!"
function sayHello() {
}
describe("given we are annonymous", () => {
it("should say hello world", () => {
Test.assertEquals(sayHello(), "Hello World!");
});
});
Function 'pick' in the Underscore.js (http://underscorejs.org/#pick)
"Return a copy of the object, filtered to only have values for the whitelisted keys (or array of valid keys). Alternatively accepts a predicate indicating which keys to pick."
_.pick({name: 'moe', age: 50, userid: 'moe1'}, 'name', 'age');
// {name: 'moe', age: 50}
_.pick({name: 'moe', age: 50, userid: 'moe1'}, function(value, key, object) {
return typeof value == 'number';
});
// {age: 50}
var _ = {};
_.pick = (target, ...keys) => {
if (typeof keys[0] == 'function') {
var predicate = keys[0];
keys = Object.keys(target);
return keys.reduce((obj, key) => {
return predicate(target[key], key, target) ? (obj[key] = target[key], obj) : obj;
}, {})
}
return keys.reduce((obj, key) => {
return obj[key] = target[key], obj;
}, {});
};
var result;
result = _.pick({name: 'moe', age: 50, userid: 'moe1'}, 'name', 'age');
Test.assertSimilar(result, {name: 'moe', age: 50});
result = _.pick({name: 'moe', age: 50, userid: 'moe1'}, function(value, key, object) {
return typeof value == 'number';
});
Test.assertSimilar(result, {age: 50});
If it does not work, just say :).
template<typename T>
T add(T a, T b){
return a-(-b);
}
// TODO: Replace examples and use TDD development by writing your own tests
Describe(somathing)
{
It(basic)
{
Assert::That(add(1024, 1024), Equals(2048));
Assert::That(add(add(1.0, 1.5), add(32.0, 64.5)), Equals(99));
}
It(negativ_plus_positiv){
Assert::That(add(1024, -1024), Equals(0));
Assert::That(add(-512, 256));
}
};
bool Or(bool a, bool b){
if(!a){
if(!b){
return false;
}
}
return true;
}
bool Xor(bool a, bool b){
return a != b;
}
bool And(bool a, bool b){
if(a){
if(b){
return true;
}
}
return false;
}
// TODO: Replace examples and use TDD development by writing your own tests
Describe(AND_OR_XOR)
{
It(AND)
{
Assert::That(And(true, false), Equals(false));
Assert::That(And(false, true), Equals(false));
Assert::That(And(true, true), Equals(true));
Assert::That(And(false, false), Equals(false));
}
It(OR)
{
Assert::That(Or(true, false), Equals(true));
Assert::That(Or(false, true), Equals(true));
Assert::That(Or(true, true), Equals(true));
Assert::That(Or(false, false), Equals(false));
}
It(XOR)
{
Assert::That(Xor(true, false), Equals(true));
Assert::That(Xor(false, true), Equals(true));
Assert::That(Xor(true, true), Equals(false));
Assert::That(Xor(false, false), Equals(false));
}
};
Parses an expression.
def parse(expr): #The main parser
ps = 0 #Number of open parentheses
cval = 0 #Current value
op = "+" #Current operation
accum = "" #Accumulating value
for i in range(len(expr)):
c = expr[i]
if c in ["+","-"] and not ps: #Operation not inside parens
if op=="+": #Addition
cval+=parse_fact(accum)
else: #Subtraction
cval-=parse_fact(accum)
accum = "" #Reset the value
op = c #New operation once that was calculated
else:
if c=="(": ps+=1 #Open paren
if c==")": ps-=1 #Close paren
accum+=c #Add a character to accumulating value
if op=="+": #Do the operation one more time
cval+=parse_fact(accum)
else:
cval-=parse_fact(accum)
return cval
def parse_fact(term):
ps = 0
cval = 1
op = "*"
accum = ""
for i in range(len(term)):
c = term[i]
if c in ["*","/"] and not ps:
if op=="*":
cval*=parse_val(accum)
else:
cval/=parse_val(accum)
accum = ""
op = c
else:
if c=="(": ps+=1
if c==")": ps-=1
accum+=c
if op=="*":
cval*=parse_val(accum)
else:
cval/=parse_val(accum)
return cval
def parse_val(val):
if val[0] == "(": #Parenthetical expression
return parse(val[1:-1]) #Cut off parentheses and reevaluate
else:
return float(val) #Not parenthetical
test.expect(parse("5")==5,"FAILED TEST CASE 1 (5)")
test.expect(parse("5+5")==10,"FAILED TEST CASE 2 (5+5)")
test.expect(parse("5*5")==25,"FAILED TEST CASE 3 (5*5)")
test.expect(parse("5*5+5")==30,"FAILED TEST CASE 4 (5*5+5)")
test.expect(parse("5*5+5/5")==26,"FAILED TEST CASE 5 (5*5+5/5)")
test.expect(parse("5*(5+5)/5")==10,"FAILED TEST CASE 6 (5*(5+5)/5)")
test.expect(parse("5*(5+(10/2))/5")==10,"FAILED TEST CASE 7 (5*(5+(10/2))/5)")
test.expect(parse("(60/5)-4/29-61+96")==46.86206896551724,"FAILED TEST CASE 8")
Takes the square root of an int and returns a double.
double sqrt (int a,int accuracy=20) {
double out = a;
for(int i=0;i<accuracy;i++) {
out = (out+a/out)/2;
}
return out;
}
// TODO: Replace examples and use TDD development by writing your own tests
Describe(square_root)
{
It(should_take_square_root)
{
Assert::That(sqrt(4), Equals(2));
Assert::That(sqrt(16), Equals(4));
Assert::That(sqrt(169), Equals(13));
}
};