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.
add(X, Y, R) :- R is X + Y + 1.
ref_add(X, Y, R) :- R is X + Y.
fixed_test(x = 1, y = 2, expected = 3).
fixed_test(x = 3, y = 4, expected = 7).
fixed_test(x = X, y = Y, expected = E) :-
member((X, Y, E), [(1, 2, 3), (3, 4, 7)]).
random_test(x = X, y = Y, expected = E) :-
random_between(-100, 100, X),
random_between(-100, 100, Y),
ref_add(X, Y, E).
repeated_random_test(X, Y, E) :-
between(1, 5, _),
random_test(X, Y, E).
:- begin_tests(adder).
:- include(adder).
do_test(x = X, y = Y, expected = E) :-
findall(R, add(X, Y, R), R),
assertion(R == [E]).
test(fixed, [forall(fixed_test(X, Y, E))]) :- do_test(X, Y, E).
test(random, [forall(repeated_random_test(X, Y, E))]) :- do_test(X, Y, E).
:- end_tests(adder).
add(X, Y, R) :- R is X + Y + 1.
with(_ : C) :- C.
:- begin_tests(adder).
:- include(adder).
test(showing_input) :-
X = 1, Y = 2, E = 3,
add(X, Y, R),
assertion(with((x = X, y = Y, expected = E): (R == E))).
:- end_tests(adder).
You must display literally the difference between two dates textual
Exemple input howManyTimesBetween("1995-12-02 and 2010-01-05")
Will return "There are 14 year(s), 10 month(s), 8 day(s) between 1995-12-02 and 2010-01-05"
Constraints and permissions
If constraints are not respected, the function should return "Your question is strange"
- The two dates can be inverted (the oldest can be at start or end), and will give the same gap between the twice dates
- If there are no months/day/years gap. Don't display it in the sentence (exemple :
howManyTimesBetween("2010-01-05 and 2010-01-10")
will return"There are 5 day(s) between 1995-12-02 and 2010-01-05"
) - If the two date are the same, will return "Dates are equals"
- The date format is Y-m-d (conforming to https://www.php.net/manual/fr/datetime.format.php). There is not hours or others
- The sentence should always do "{date} and {date}"
- The end of the response sentence will is the same than the input whatever the order of dates
function howManyTimesBetween(string $sentence): string
{
$errorMessage = 'Your question is strange';
$datesString = explode(' and ', $sentence);
if (count($datesString) !== 2) {
return $errorMessage;
}
$date1 = DateTime::createFromFormat('Y-m-d', $datesString[0]);
$date2 = DateTime::createFromFormat('Y-m-d', $datesString[1]);
if ($date1 === false or $date2 === false) {
return $errorMessage;
}
$diffStrings = [];
if ($date1 == $date2) {
return 'Dates are equals';
}
$diff = $date1->diff($date2);
if ($diff->y) {
$diffStrings[] = $diff->y.' year(s)';
}
if ($diff->m) {
$diffStrings[] = $diff->m.' month(s)';
}
if ($diff->d) {
$diffStrings[] = $diff->d.' day(s)';
}
return 'There are '.implode(', ', $diffStrings).' between '.$sentence;
}
<?php
use PHPUnit\Framework\TestCase;
/**
* test function names should start with "test"
*/
class HowManyTimesTest extends TestCase
{
public function test_simple(): void
{
$this->assertEquals('There are 14 year(s), 10 month(s), 3 day(s) between 1995-12-02 and 2010-10-05',
howManyTimesBetween('1995-12-02 and 2010-10-05'));
$this->assertEquals('There are 14 year(s), 10 month(s), 3 day(s) between 2010-10-05 and 1995-12-02',
howManyTimesBetween('2010-10-05 and 1995-12-02'));
$this->assertEquals('There are 3 day(s) between 2010-01-05 and 2010-01-08',
howManyTimesBetween('2010-01-05 and 2010-01-08'));
$this->assertEquals('There are 1 month(s), 3 day(s) between 2010-01-05 and 2010-02-08',
howManyTimesBetween('2010-01-05 and 2010-02-08'));
}
public function test_equals(): void
{
$this->assertEquals('Dates are equals', howManyTimesBetween('1995-12-02 and 1995-12-02'));
}
public function test_errors(): void
{
$this->assertEquals('Your question is strange', howManyTimesBetween('1995-12-02 and 2010-01-02 and 2010-01-05'));
$this->assertEquals('Your question is strange', howManyTimesBetween('1995-12-02 or 1995-12-02'));
$this->assertEquals('Your question is strange', howManyTimesBetween('2010-01-05 or 2010-01-05'));
$this->assertEquals('Your question is strange', howManyTimesBetween('1995-12-02,2010-01-05'));
$this->assertEquals('Your question is strange', howManyTimesBetween('...'));
$this->assertEquals('Your question is strange', howManyTimesBetween('02/04/1995 and 03/04/1995'));
$this->assertEquals('Your question is strange', howManyTimesBetween('1995-12-02 10:10 and 2010-01-05 11:11'));
$this->assertEquals('Your question is strange', howManyTimesBetween('1995-12-02 10:10 and 1995-12-02 10:10'));
}
}
Combination of List
Instructions
Below are Instructions for this Kumite.
Introduction
Given the two list or arrays, filter and combine the numbers into one list or arrays. There will only be numbers in the list.
Requirements
- There will be no negative number in the list
- The list must be ordered in ascending order.
- There must be no repeating number in the list.
- It must support an empty list.
Test Samples
Below are the test sample for this excercise
# Multiple list should be able to combine into one list
combine_list([1,2,3],[4,5,6])
> [1,2,3,4,5,6]
# Final list should be sorted
combine_list([3,2,1,5],[6,8,7])
> [1,2,3,5,6,7,8]
# There must be no repeating number in the list
combine_list([4,5,6],[7,7,8])
>[4,5,6,7,8]
# The will be no negative number in the list
combine_list([4,5,8],[99,0,11,665,-245])
> [0,4,5,8,11,99,665]
def combine_list(list1,list2):
return list(set(list(filter(lambda c: (c > 0), list1 + list2))))
import codewars_test as test
import random
# TODO Write tests
import solution # or from solution import example
def answer(list1,list2):
return list(set(list(filter(lambda c: (c > 0), list1 + list2))))
def randomTestGen(min,max,numTime):
newList = []
for i in range(numTime):
r = random.randint(min,max)
newList.append(r)
return newList
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Sample test case")
def test_group():
@test.it("List should be combine into one list")
def test_case():
test.assert_equals(combine_list([1,2,3],[4,5,6]), [1,2,3,4,5,6])
@test.it("List should be sorted")
def test_case():
test.assert_equals(combine_list([3,2,1,5],[6,8,7]),[1,2,3,5,6,7,8])
@test.it("There must be no repeating numbers")
def test_case():
test.assert_equals(combine_list([4,5,6],[7,7,8]), answer([4,5,6],[7,7,8]))
@test.it("Must support empty list")
def test_case():
test.assert_equals(combine_list([],[]), [])
@test.describe("Hidden Test Case")
def test_group():
@test.it("Random test case")
def test_case():
for i in range(20):
t1 = randomTestGen(-5,30, random.randint(5,100))
t2 = randomTestGen(-5,30, random.randint(5,100))
test.assert_equals(combine_list(t1,t2), answer(t1,t2))
output "another value".
#include <iostream>
#include <string>
int voice(){
std::string a,b;
std::cin>>a>>b;
std::cout<<"another value";
return 0;
}
// TODO: Replace examples and use TDD by writing your own tests
Describe(any_group_name_you_want)
{
It(should_do_something)
{
Assert::That("another value", Equals("another value"));
}
};
There is a tree.
We define "cut the branch" as deleting one of its non-leaf nodes and making its sons its equal.
A root can also be deleted to form 2 seperate trees.
An example:
1->2, 2->3, 2->4
after deleting 2:
1->3, 1->4
after deleting 1:
3, 4(two seperate trees)
Your job is to decide the maximal amouts of trees you get when there are not any branches left for you to cut.
The input will be like this:
vector1 1 2 2
| | |
/ / /
vector2 2 3 4
#include <vector>
using namespace std;
int CutTheBranch(vector<int> fir, vector<int> sec){
int thing[20005];
for(int i=0;i<20005;i++)thing[i]=0;
int k=sec.size();
for(int i=0;i<k;i++)thing[fir[i]]++;
int cnt=0;
for(int i=0;i<20005;i++)if(thing[i]!=0)cnt++;
return cnt;
}
// TODO: Replace examples and use TDD by writing your own tests
Describe(You_should_pass_this)
{
It(basic)
{
std::vector<int> a1,b1,a2,b2;
a1.push_back(1);
a1.push_back(2);
a1.push_back(2);
a2.push_back(2);
a2.push_back(3);
a2.push_back(4);
b1.push_back(1);
b2.push_back(2);
Assert::That(CutTheBranch(a1,a2), Equals(2));
Assert::That(CutTheBranch(b1,b2), Equals(1));
//Explanation: The second case consists of only one parent node, so it is cut to form 1 tree
}
It(Random)
{
std::vector<int> r1,r2;
int rt[20005];
int n;
for(int i=0;i<20005;i++)rt[i]=0;
srand(time(NULL));
n=rand()%10000;
for(int i=0;i<n;i++){
int j1=rand()%20000,j2=rand()%20000;
r1.push_back(j1);
r2.push_back(j2);
rt[j1]++;
}
int cnt=0;
for(int i=0;i<20005;i++)if(rt[i]!=0)cnt++;
Assert::That(CutTheBranch(r1,r2),Equals(cnt));
}
};
Get Max of two integers
section .text
global max ; declare max function
max: ; int max(int a, int b)
cmp rdi, rsi ; compare a ?= b
jle _lower ; jump to lower if a <= b
jmp _greater ; jump to greater if a > b
_lower:
mov rax, rsi ; assgine rax to b
jmp _end ; end program
_greater:
mov rax, rdi ; assgine rax to a
_end:
ret
#include <criterion/criterion.h>
int max(int, int);
Test(max, should_return_max) {
cr_assert_eq(max(1, 2), 2);
cr_assert_eq(max(3, 2), 3);
}
Macro to get max of two integers
can be used as a new pseudo-command
; A macro with two parameters
; Implements actual int max(int a, int b)
%macro _max 2
cmp %2, %1 ; compare a ?= b
jle _lower ; jump to lower if a <= b
jmp _greater ; jump to greater if a > b
_lower:
mov rax, %1 ; assgine rax to b
jmp _end ; end program
_greater:
mov rax, %2 ; assgine rax to a
_end:
ret
%endmacro
section .text
global max ; declaring int max(int a, int b)
max:
_max rdi, rsi ; using inner _max macro
ret
#include <criterion/criterion.h>
int max(int, int);
Test(max, should_return_max) {
cr_assert_eq(max(3, 2), 3);
}
Iterating over two vectors at the same time till end of one of them
#include <vector>
#include <tuple>
#include <iostream>
template <class T, class U>
void iterateTwoVectors(std::vector<T> A, std::vector<U> B)
{
for (auto [a,b] = std::tuple{A.begin(), B.begin()}; a != A.end() && b != B.end(); a++, b++)
{
std::cout << *a << ":" << *b << "\n";
}
}
// TODO: Replace examples and use TDD by writing your own tests
Describe(iterating)
{
It(should_iterate_both)
{
iterateTwoVectors<int, char>({1, 'a', 3}, {'a', 'b'});
}
};
enumerating over vector, equivelent to python's enumerate(list)
#include <vector>
#include <tuple>
#include <iostream>
template <class T>
void enumerate(std::vector<T> A)
{
for(auto [a,i]=std::tuple{A.begin(), 0}; a < A.end(); a++, i++)
{
std::cout << i << ":" << *a << "\n";
}
}
Describe(enumerating)
{
It(should_enumerate)
{
enumerate<int>({1, 5, 'a', 32});
}
};