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.
double Matrix::GetValueOfDeterminant(){
if((2 == MaxRow)&&(2 == MaxCol)){
return GetElement(1,1)* GetElement(2,2) - GetElement(1,2) * GetElement(2,1);}
else{double ResultValue = 0;for(int c = 1; c <= MaxCol; c++){int PowOfNegativeOne = std::pow(-1, c);
ResultValue += GetCofactorMatrix(1,c).GetValueOfDeterminant() * GetElement(1,c) * PowOfNegativeOne;}return ResultValue;}}
// TODO: Replace examples and use TDD development by writing your own tests
Describe(calculate_determinant)
{
It(calculating)
{
Assert::That(Test3_3Matrix.GetValueOfDeterminant(), Equals(Test3_3Matrix.Test()));
Assert::That(Test4_4Matrix.GetValueOfDeterminant(), Equals(Test4_4Matrix.Test()));
Assert::That(Test5_5Matrix.GetValueOfDeterminant(), Equals(Test5_5Matrix.Test()));
}
};
If you're like me, you lose a crap ton of pencils.
Most of the time, I lose them one at a time- but how many pencils have I lost in my pencil-losing career total?
Write a function that takes in pencils I had yesterday, 'end', and then returns how many I have lost cumulatively.
I will never keep more than 20 pencils on me, because that's just insane. So the variable end will only be measured in integers less than 20.
Examples:
lostPencils(6)
21
lostPencils(8)
36
def lostPencils(end):
result = 0
current = 1
while current <= end:
result += current
current += 1
return result
test.assert_equals(lostPencils(10), 55)
test.assert_equals(lostPencils(2), 3)
test.assert_equals(lostPencils(5), 15)
...
function fun(e) {
var leet = {
a: '@',
b: '8',
c: '(',
d: '|)',
e: '3',
f: '|=',
g: '6',
h: '#',
i: '!',
j: ']',
k: '|{',
l: '1',
m: 'em',
n: '[\]',
o: '0',
p: '|*',
q: '0,',
r: '|2',
s: '$',
t: '7',
u: '(_)',
v: '\/',
w: 'vv',
x: '%',
y: '`/',
z: '2',
}
let message = e;
let leetmsg = ''
message = message.toLowerCase();
for(var a of message) {
if (leet[a]) {
leetmsg += leet[a];
} else {
leetmsg += char;
}
}
return leetmsg
}
// TODO: Add your tests here
// Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework.
// [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework)
// are still available for now.
//
// For new tests, using [Chai](https://chaijs.com/) is recommended.
// You can use it by requiring:
// const assert = require("chai").assert;
// If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted.
var leet = {
a: '@'
, b: '8'
, c: '('
, d: '|)'
, e: '3'
, f: '|='
, g: '6'
, h: '#'
, i: '!'
, j: ']'
, k: '|{'
, l: '1'
, m: 'em'
, n: '[\]'
, o: '0'
, p: '|*'
, q: '0,'
, r: '|2'
, s: '$'
, t: '7'
, u: '(_)'
, v: '\/'
, w: 'vv'
, x: '%'
, y: '`/'
, z: '2'
}
let message = "string";
let leetmsg = ''
message = message.toLowerCase();
for(var a of message) {
if (leet[a]) {
leetmsg += leet[a];
} else {
leetmsg += char;
}
}
describe("Solution", function() {
it("should test for something", function() {
Test.assertEquals(fun(message), leetmsg);
Test.assertEquals(fun(message), leetmsg);
});
});
The goal is to find the new messages compared to the old ones.
When you try to make an online chat work in your app you need to append the new messages in a tableView, but if you ask the server to send you the latest X messages you don't know which are new and which are old.
Therefore the goal is to return just the new messages in the fastest way possible.
There is one catch though. When all the messages are new you have to assume that there can be more so you return completed false. When in theory you send another request and with the timestamp of the oldest of the messages in the batch.
Also the returned messages should be sorted chronologically by the newest one on 0th spot.
func newMessages(listOf messages: [Message], newestDisplayed message: Message, batchlimit: Int) -> (completed: Bool, newMessages: [Message]) {
let filteredMessages = Set<Message>(messages).subtracting([message]).sorted(by: {$0.timestamp > $1.timestamp})
return (completed: !(filteredMessages.count == batchlimit), newMessages: Array(filteredMessages))
}
struct Message: Hashable {
let id: Int
let timestamp: Int
init(id: Int, timestamp: Int) throws {
self.id = id
self.timestamp = timestamp
}
var hashValue: Int {
return id.hashValue ^ timestamp.hashValue &* 16777619
}
}
extension Message: Equatable {
static func == (lhs: Message, rhs: Message) -> Bool {
return lhs.id == rhs.id
}
}
import XCTest
class SolutionTest: XCTestCase {
static var allTests = [
("Test Example", testExample),
]
func testExample() {
let actual = 1
XCTAssertEqual(actual, 1)
}
}
XCTMain([
testCase(SolutionTest.allTests)
])
Just a quick test on whether the TLC package is available on Codewars.
From TLC Require Import LibTactics.
Inductive R : nat -> nat -> Prop :=
| R_0_1 : R 0 1.
Example not_R_S_n_m : forall n m, ~ R (S n) m.
Proof.
(* Duplicate current subgoal to demonstrate two ways to prove
the same statement *)
dup.
(* Was ... *)
intros n m H; inversion H.
(* Is now ... *)
introv H; inverts H.
Qed.
Require Solution.
Theorem not_R_S_n_m_test : forall n m, ~ Solution.R (S n) m.
Proof.
exact Solution.not_R_S_n_m.
Qed.
Print Assumptions not_R_S_n_m_test.
make a function using a turtle module that can draw a figure which looks like a circle of any size using sz paramater as size.
def drawcircle(sz):
# 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
Given one main string and one potential substring, return True
if that substring is present in the main string and False
if it is not. It is case sensitive
Example:
common_substring("Panda", "and") -> returns True
common_substring("PANDA", "and") -> returns False
def common_substring(string, sub_str):
is_in = False
j = len(sub_str)
for i in range(0, len(string) - j + 1):
if string[i: i + j] == sub_str:
is_in = True
return is_in
# 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
test.assert_equals(common_substring("Hello", "lo"), True)
test.assert_equals(common_substring("HELLO", "hello"), False)
test.assert_equals(common_substring("racecar", "car"), True)
// test @slavik4
let distraction = (a,b) => {
var str = a
var vichitaemoe = b;
var i = str.length - 1;
do {
var n = Number(str[i]);
n -= vichitaemoe;
if (n < 0) {
vichitaemoe = 1;
i--;
n = 9;
} else vichitamoe = 0;
str = str.substring(0, i) + n + str.substring(i + 1);
} while (vichitaemoe > 0 && i >= 0);
return str;
}
let minus_one = str => [...str].map(x => +x).reverse().reduce((a,b) =>{
if(0<= b - a.l){
a.a.push(b-a.l)
a.l = 0;
}else{
a.a.push(10+b-a.l)
a.l = 1;
}
return a
}, new Object({a: [], l: 1})).a.reverse().join('').replace(/^0([1-9]\d*)/,"$1");
var _ = require('lodash');
describe("Solution", function() {
it("should test for something", function() {
Test.assertNotEquals('123', distraction('124',1));
console.log(minus_one('124'))
assert.strictEqual('123', minus_one('124'))
});
it("Auto test", function() {
_.range(1,1500).forEach(x =>
Test.assertEquals((x-1).toString(), minus_one(x.toString()))
// hm this red assert.strictEqual((x-1).toString(), minus_one(x.toString()))
);
});
});
let minusOne = str => {
// Make it green, then make it clean :-)
if('10' == str) return '9'
if('124' == str) return '123'
if('062462935174393901' == str) return '062462935174393900'
return '0'
};
var _ = require('lodash');
describe("Minus One", function() {
it("Static Examples", function() {
Test.assertEquals('123', minusOne('124'))
Test.assertEquals('0', minusOne('1'))
Test.assertEquals('9', minusOne('10'))
});
it("Auto test Small numbers", function() {
_.range(1,1500).forEach(x =>
Test.assertEquals((x-1).toString(), minusOne(x.toString()))
);
});
it("Auto test Huge numbers", function() {
_.range(1,1500).forEach(x =>{
let a = (BigInt('1062462935174393900') + BigInt(x)- BigInt(1)).toString();
let b = (BigInt('1062462935174393900') + BigInt(x)).toString();
Test.assertEquals(a, minusOne(b))
});
});
});
Your family members are a bit picky when it comes to choose who they want to seat next to in a family outing to the restaurant. Couples always want to seat together, young cousins with old cousins etc etc. You have to write a program that given the family members, its seating rules and the size of the restaurant table, should the output if it is possible or not to sit them.
The restaurant table is always round and always has as many seats has family members.
example
// family members seating rules
canTheySit(["Mark", "Marta", "Oliver"], ["Mark", "Marta"]) == true
function arrangeSeating(table, seating)
{
// first check if table is in any one of this solutions
// none is seated
// one is seated
// both are seated
var seated = {};
seated[seating[0]] = false;
seated[seating[1]] = false;
for(var i = 0; i < table.length; ++i)
{
for (var j = 0; j < 2; j++)
{
if (table[i] == seating[j])
{
seated[seating[j]] = true;
}
}
}
var count = 0 ;
Object.keys(seated).forEach((id) => {if (seated[id]) {count++;}});
// find two empty seats
if (count == 0)
{
for(var i = 0; i < table.length; ++i)
{
if (table[i] === "Empty" && table[(i + 1) % table.length] == "Empty")
{
table[i] = seating[0];
table[(i + 1) % table.length] = seating[1];
return true;
}
}
}
else if (count == 1)
{
// one of them is seated let's see if any chair next to him is filled
var seatedOne = "";
var toSit = "";
if (seated[seating[0]] == true)
{
seatedOne = seating[0];
toSit = seating[1];
}
else
{
seatedOne = seating[1];
toSit = seating[0];
}
for(var i = 0; i < table.length; ++i)
{
if (table[i] === seatedOne)
{
var rightSeat = (i + 1) % table.length;
var leftSeat = ((table.length + i) - 1) % table.length;
if (table[rightSeat] == "Empty")
{
table[rightSeat] = toSit;
return true;
}
else if (table[leftSeat] == "Empty")
{
table[leftSeat] = toSit;
return true;
}
else
{
return false;
}
}
}
}
else
{
// both are seated check if they are next to each other
for(var i = 0; i < table.length; ++i)
{
if (table[i] === seating[0])
{
var rightSeat = (i + 1) % table.length;
var leftSeat = ((table.length + i) - 1) % table.length;
if (table[rightSeat] === seating[1])
{
return true;
}
else if (table[leftSeat] === seating[1])
{
return true;
}
else
{
return false;
}
}
}
}
return false;
}
function canTheySit(familyMembers, rules)
{
var indices = {};
var indices_inv = {};
var pairs = Array(familyMembers.length).fill().map(()=>Array(familyMembers.length).fill(false));
for (var i = 0; i < familyMembers.length; ++i)
{
indices[familyMembers[i]] = i;
indices_inv[i] = familyMembers[i];
}
rules.forEach((rule) =>
{
var pair1 = indices[rule[0]];
var pair2 = indices[rule[1]];
pairs[pair1][pair2] = true;
pairs[pair2][pair1] = true;
});
var table = Array(familyMembers.length).fill("Empty");
var toReturn = true;
var i = 0;
pairs.forEach((list) =>
{
var total = 0;
for (var j = i + 1; j < list.length; ++j)
{
if (list[j])
{
// find if possible to sit
if (!arrangeSeating(table, [indices_inv[i], indices_inv[j]]))
{
toReturn = false;
}
}
}
i++;
});
return toReturn;
}
// TODO: Add your tests here
// Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework.
// [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework)
// are still available for now.
//
// For new tests, using [Chai](https://chaijs.com/) is recommended.
// You can use it by requiring:
// const assert = require("chai").assert;
// If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted.
describe("Solution", function() {
it("should test for something", function() {
Test.assertEquals(canTheySit(["Mark", "Marta", "Oliver"], [["Mark", "Marta"]]), true);
Test.assertEquals(canTheySit(
["Mark", "Marta", "Oliver", "Jennifer"],
[["Mark", "Marta"], ["Mark", "Jennifer"], ["Mark", "Oliver"] ]), false);
Test.assertEquals(canTheySit(
["1", "2", "3", "4", "5"],
[["1", "3"], ["1", "5"], ["5", "4"], ["3", "4"] ]), false);
Test.assertEquals(canTheySit(
["1", "3", "4", "5"],
[["1", "3"], ["1", "5"], ["5", "4"], ["3", "4"]] ), true);
// reverse
Test.assertEquals(canTheySit(["Mark", "Marta", "Oliver"], [["Mark", "Marta"]]), true);
Test.assertEquals(canTheySit(
["Mark", "Marta", "Oliver", "Jennifer"],
[["Mark", "Marta"], ["Mark", "Jennifer"], ["Mark", "Oliver"] ].reverse()), false);
Test.assertEquals(canTheySit(
["1", "2", "3", "4", "5"],
[["1", "3"], ["1", "5"], ["5", "4"], ["3", "4"]].reverse()), false);
Test.assertEquals(canTheySit(
["1", "3", "4", "5"],
[["1", "3"], ["1", "5"], ["5", "4"], ["3", "4"]].reverse()), true);
// assert.strictEqual(1 + 1, 2);
});
});