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.
Suppose you have a software, that will distribute invoices to different billing service providers.
You have a user interface, where you can set the ratio in which the bills are to be distributed to the providers. Back in the software, all bills run in a shuffle function. This function is called with the config from the user interface, that contains the providers and the ratio in which the providers should be chosen.
The Function is generic, so you can send any type you want in the function. This is a very easy way to implement a dynamic load distribution.
If you call the function 1000 times or more, the distribution is very close by your configuration.
using System;
using System.Collections.Generic;
using System.Linq;
namespace Solution
{
public class ObjectShuffler
{
private Random rnd = new Random();
public T Shuffle<T>(Dictionary<T, int> parameterDict)
{
//Remove wrong configuration.
parameterDict = (from i in parameterDict
where i.Value > 0
select i).ToDictionary(x => x.Key, x => x.Value);
//Error Handling
if (parameterDict.Count == 0)
{
throw new Exception("Can't shuffle an empty list.");
}
//Do Work
var sumItemsValue = (from x in parameterDict select x.Value).Sum();
var randNr = this.rnd.Next(1, sumItemsValue + 1);
var stepSum = 0;
foreach (var item in parameterDict)
{
stepSum = stepSum + item.Value;
if (randNr <= stepSum)
{
return item.Key;
}
}
// This can't happen.
throw new Exception("Run to far.");
}
}
}
using NUnit.Framework;
using System;
using System.Collections.Generic;
namespace Solution {
[TestFixture]
public class SolutionTest
{
[Test]
public void Test1()
{
// This test is a usage example.
var results = new Dictionary<String, int>();
results.Add("Provider1", 0);
results.Add("Provider2", 0);
results.Add("Provider3", 0);
var config = new Dictionary<String, int>();
config.Add("Provider1", 10);
config.Add("Provider2", 30);
config.Add("Provider3", 50);
var shuffler = new ObjectShuffler();
for (int i = 0; i < 9000; i++)
{
var key = shuffler.Shuffle(config);
results[key]++;
}
foreach (var r in results)
{
Console.WriteLine($"{r.Key} {r.Value}");
}
}
}
}
I've done a 7kyu kata. The task was to return the same table, but with one column changed.
Say they want to to upper one column, but other columns should remain the same.
In that kata there were only 4 columns.
And all top soulutions was like this:
SELECT column1, column2, column3, UPPER(column4)
But i came with an idea and soulution for the case when there are say 10 columns.
Instead of making a big selecet statement we can do like this:
SELECT *, UPPER(column5) as column5
FROM test_table
results = run_sql.select(:column5)
describe :test_table do
it "column5 should be uppercase" do
expect(results[:column5][:column5]).to eq "TEXT5"
end
end
just trying how this works
public func holabro(){
a=1
return ""
}
import XCTest
// XCTest Spec Example:
// TODO: replace with your own tests (TDD), these are just how-to examples to get you started
class SolutionTest: XCTestCase {
static var allTests = [
("Test Example", testExample),
]
func testExample() {
let actual = 1
XCTAssertEqual(actual, 1)
}
}
XCTMain([
testCase(SolutionTest.allTests)
])
public class ThirdAngle {
public static int otherAngle(int angle1, int angle2) {
return 180-(angle1+angle2);
}
}
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");
}
}
char* Hi (void)
{char* ans;
asprintf(&ans, "Hello World.");
return ans;}
#include <criterion/criterion.h>
const char* Hi ();
Test(the_hello_world_function, should_pass_all_the_tests_provided) {
cr_assert_eq(strcmp(Hi(),"Hello World."), 0);
char *p = Hi();
*p = 'X';
printf("%s\n",p);
}
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.