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.
const chai = require("chai");
const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:
chai.config.truncateThreshold = 0;
// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
// Uncomment the following to use the old assertions:
const Test = require("@codewars/test-compat");
describe("Solution", function() {
it("should test for something", function() {
Test.assertEquals(1 + 1, 2);
assert.strictEqual(1 + 1, 2);
});
});
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const chai = require("chai");
const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:
chai.config.truncateThreshold = 0;
// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
// Uncomment the following to use the old assertions:
const Test = require("@codewars/test-compat");
describe("Solution", function() {
it("should test for something", function() {
Test.assertEquals(1 + 1, 2);
assert.strictEqual(1 + 1, 2);
});
});
Your boss give you a task to format some integer numbers like this:
123456789
-> 123,456,789
So, you should write a function f
which recieves a integer number and returns a string which every 3 consecutive digits are splitted with ,
symbol from left to right.
def f(n):
G = 3
s = str(n)
r = len(s) % G
def make(s):
if r:
yield s[:r]
for i in range(r, len(s), G):
yield s[i:i+G]
return ','.join(make(s))
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
test.assert_equals(f(100), '100')
test.assert_equals(f(1000), '1,000')
test.assert_equals(f(12345), '12,345')
test.assert_equals(f(123456789), '123,456,789')
test.assert_equals(f(10000000000), '10,000,000,000')
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(1 + 1, 2)
reverse the string passed as an arg and return the result
function revstr(str) {
i = str.length; newstr = "";
while (i > 0) {
newstr += str[i - 1]; i--;
}
return newstr;
}
const chai = require("chai");
const assert = chai.assert;
describe("Solution", function() {
it("return reversed", function() {
assert.strictEqual(revstr("ok hello"), "olleh ko");
});
});
Return the character with the greatest occurance in a string
aaabbc -> a
abc -> a
abbcc -> b
cba -> c
function gtc(str) {
const map = {}
for(let char of str) {
if(map[char]) {
map[char] = map[char] + 1
}else {
map[char] = 1
}
}
let result = str[0]
for(let key in map) {
if(map[key] > map[result]) {
result = key
}
}
return result
}
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const chai = require("chai");
const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:
// chai.config.truncateThreshold = 0;
// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
// Uncomment the following to use the old assertions:
// const Test = require("@codewars/test-compat");
describe("Solution", function() {
it("should pass", function() {
assert.strictEqual(gtc('abc'), 'a');
assert.strictEqual(gtc('abbcc'), 'b');
assert.strictEqual(gtc('abbc'), 'b');
});
});
takes two lists that are already sorted, and merges them together.
another simple solution but with higher order (O) is to simply sorted(a + b)
the two lists.
def merge_lists(a, b):
"""
takes two sorted lists, and merges them
"""
sorted_list = []
# grab inital values
a_i = 0
b_i = 0
# while lists are not empty
while len(a) != a_i and len(b) != b_i:
if a[a_i] < b[b_i]:
sorted_list.append(a[a_i])
a_i += 1
else:
sorted_list.append(b[b_i])
b_i += 1
# append whatever is remaining
[sorted_list.append(i) for i in a[a_i:]]
[sorted_list.append(i) for i in b[b_i:]]
return sorted_list
import codewars_test as test
# TODO Write tests
from solution import merge_lists# or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
a = [1,1,3,5,8,10]
b = [2,4,5,5,9]
c=[1, 1, 2, 3, 4, 5, 5, 5, 8, 9, 10]
test.assert_equals(merge_lists(a,b),c)
@test.it("test empty list")
def test_case2():
a = [1,1,3,5,8,10]
b = []
c = sorted(a+b)
test.assert_equals(merge_lists(a,b),c)
This implementation makes it fairly clear that this is an O(n log(n)) operation.
from math import log
def lsd(l,b):
s = l
for n in range(int(log(max(l),b))+1):
r = [[] for n in range(b)]
for x in s:
r[x//b**n%b].append(x)
s = [e for i in r for e in i]
return s
@test.describe("Tests")
def tests():
test.assert_equals(lsd([170, 45, 75, 90, 2, 802, 2, 66], 10), [2, 2, 45, 66, 75, 90, 170, 802])
A container that you access like a sorted container, but only sorts the parts it needs to.
Based off of quicksort, so O(N**2)
for a single access.
However, everything only needs to be sorted once, so it is O(N**2+Q)
for Q queries.
#include <iostream>
#include <utility>
#include <memory>
#include <vector>
using pii = std::pair<int, int>;
class kata {
std::vector<std::shared_ptr<pii>> ranges;
public:
std::vector<int> &data;
kata(std::vector<int> &in_data)
: data(in_data)
, ranges(in_data.size(), std::shared_ptr<pii>(new pii(0, in_data.size())))
{
}
int operator[](int index) {
for (int x : data) {
std::cout << x << ' ';
}
std::cout << "| " << ranges[index]->first << ' ' << ranges[index]->second << '\n';
int start = ranges[index]->first;
int end = ranges[index]->second;
if (end - start == 1) {
return data[index];
}
int pivot = data[index];
data[index] = data[end - 1];
data[end - 1] = pivot;
std::shared_ptr<pii> lt_pivot(new pii(start, start));
int p = start;
for (int i = start; i < end - 1; ++i) {
if (data[i] < pivot) {
int temp = data[p];
data[p] = data[i];
data[i] = temp;
ranges[p] = lt_pivot;
++p;
}
}
lt_pivot->second = p;
data[end - 1] = data[p];
data[p] = pivot;
ranges[p]->first = p;
ranges[p]->second = p + 1;
std::shared_ptr<pii> gt_pivot(new pii(p + 1, end));
for (int i = p + 1; i < end; ++i) {
ranges[i] = gt_pivot;
}
return this->operator[](index);
}
};
// TODO: Replace examples and use TDD by writing your own tests
Describe(any_group_name_you_want)
{
It(should_do_something)
{
//Assert::That("some value", Equals("another value"));
}
};
capslock
Uppercase the first character of each word in a string.public function caps($c)
{
return ucwords($c);
}
<?php
use PHPUnit\Framework\TestCase;
class UpperallTest extends TestCase
{
public function testSampleTests()
{
$this->assertEquals("Hello My Friends.", $this->Upperall->caps("hello my friends."));
}
}
In order to understand the everyday hasstle of people that suffer from dislexia my school made us do this activity:
- replace all the (A's O's E's I's) of a certain phrase with (4's 0's 3's 1's) respectively
and we did it, but it took soooo long, would you write a bit of code that does the work for me?
e.g.:
dislexifier ->
- input : "Hey Arianna, how u doing?"
- output : "H3y 4ri4nn4, h0w u d01ng?"
ps.: try to avoid just using .replace(), it will make it more fun.
class Dislexifier
{
public static String theDislexifier(String str)
{
// TODO: Do your magic here
return str.replace("a","4").replace("A","4").replace("o","0").replace("O","0").replace("e","3").replace("E","3").replace("i","1").replace("I","1");
}
}
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
// TODO: Replace examples and use TDD by writing your own tests
public class SolutionTest {
@Test
public void testDislixifier() {
assertEquals("1'm s0 hungry 1 c0uld 34t 4 b34r rn",Dislexifier.theDislexifier("I'm so hungry I could eat a bear rn"));
assertEquals("Wh4t 4r3 th000000s3???",Dislexifier.theDislexifier("What are thoooooose???"));
assertEquals("",Dislexifier.theDislexifier(""));
assertEquals("üüüü 1s just 4 f4ncy u, 4lth0ugh n0t 4s f4ncy 4s y0u",Dislexifier.theDislexifier("üüüü is just a fancy u, although not as fancy as you"));
assertEquals("щф, l1t3r4lly just g00gl3d \"russ14n l3tt3rs\", th4t sh1dd's w31rd\"",Dislexifier.theDislexifier("щф, literally just googled \"russian letters\", that shidd's weird\""));
assertEquals("Try gypsy hymns rhythm !",Dislexifier.theDislexifier("Try gypsy hymns rhythm !"));
}
}
It will get a dictionary and return a list of the keys, all sorted by their corrosponding values in increasing order.
def dict_index(dictionary, value):
dict_keys = list(dictionary)
dict_values = list(dictionary.values())
return dict_keys[dict_values.index(value)]
def dict_sort(dictionary):
dict_values = list(dictionary.values())
new_keys = []
for x in range(len(dictionary)):
max_value = max(dict_values)
dict_values.remove(max_value)
new_keys.append(dict_index(dictionary, max_value))
new_keys.reverse()
return new_keys
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(dict_sort({'a':1,'b':2,'c':-1}), ['c','a','b'])
test.assert_equals(dict_sort({'dog':25,'rat':-7}), ['rat','dog'])