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.
Write a class named Student which takes arguments:first_name, last_name, grade, avg_marks(average marks).
and can return: first_name, full_name, grade,and be able to assess perfomance by using avg_marks.
grading scheme:
0-25:B-
26-50:B+
51-75:A-
76-100:A+
class Student:
def __init__(self, first_name, last_name, grade, avg_marks):
self.first_name=first_name
self.full_name=first_name+" "+last_name
self.grade=grade
self.avg_marks=avg_marks
def assess(self):
if 0<=self.avg_marks<=25:
return "B-"
if 26<=self.avg_marks<=50:
return "B+"
if 51<=self.avg_marks<=75:
return "A-"
if 76<=self.avg_marks<=100:
return "A+"
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Student")
def test_group():
j=Student('John','McCandy',10,50)
k=Student('Karen','Gomez',2,95)
@test.it("First Name")
def fi_test():
test.assert_equals(j.first_name, 'John')
test.assert_equals(k.first_name,'Karen')
@test.it('Full Name')
def fu_test():
test.assert_equals(j.full_name,'John McCandy')
test.assert_equals(k.full_name,'Karen Gomez')
@test.it("Grade")
def cl_test():
test.assert_equals(j.grade,10)
test.assert_equals(k.grade,2)
@test.it(" Assess Average Marks")
def av_test():
test.assert_equals(j.assess(),'B+')
test.assert_equals(k.assess(),'A+')
def is_num(num):
return type(num) in (int,float)
# return type(num).__name__=="int" or type(num).__name__=="float"
def used_num(num):
return isinstance(num,(int,float))
# return isinstance(num,int) or isinstance(num,float)
import codewars_test as test
# TODO Write tests
# import solution # or from solution import example
from solution import *
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(1 + 1, 2)
test.assert_equals(True,is_num(1))
test.assert_equals(True,is_num(1.1))
test.assert_equals(False,is_num(True))
test.assert_equals(True,used_num(-130))
test.assert_equals(True,used_num(43.2))
test.assert_equals(True,used_num(False))
from math import floor
def how_many_bucks(buy,sold,tax):
return max(1,floor(sold-(tax/100)))-buy
import codewars_test as test
# TODO Write tests
# import solution # or from solution import example
from solution import how_many_bucks
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(1 + 1, 2)
test.assert_equals(1,how_many_bucks(0,1,20))
test.assert_equals(4,how_many_bucks(0,5,20))
:)
def count_arr(arr):
mn=min(arr)
mx=max(arr)
d={}
for _ in range(mn,mx+1):
d[_]=0
for val in arr:
d[val]+=1
acc=[]
for num in range(mn,mx+1):
for _ in range(d[num]):
acc.append(num)
return acc
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
arr=[1,-39,33,13,53,43,100,-100,2,3,4]
sort1=sorted(arr)
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(count_arr(arr), sort1)
works for empty array too
#returns the index of val if val is in the array, else -1 if val is not in the array.
#precondition: arr must be sorted in ascending order
def binary_search(arr,val):
i=-1
j=len(arr)
while i+1!=j:
m=i+(j-i)//2
if arr[m]<val:
i=m
elif arr[m]>val:
j=m
else:
return m
return -1
import codewars_test as test
# TODO Write tests
# import solution # or from solution import example
from solution import binary_search
# test.assert_equals(actual, expected, [optional] message)
arr=[1,2,3,4,5,6,7,8]
val1=3
val2=100
val3=-1
arr2=[0]
val4=0
val5=-10
val6=10
empty=[]
val10=42
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(binary_search(arr,val1), 2)
test.assert_equals(binary_search(arr,val2), -1)
test.assert_equals(binary_search(arr,val3), -1)
test.assert_equals(binary_search(arr2,val4), 0)
test.assert_equals(binary_search(arr2,val5), -1)
test.assert_equals(binary_search(arr2,val6), -1)
test.assert_equals(binary_search(empty,val10), -1)
class Solution{
public static int linear_search(int[] arr,int val){
int i=0;
while (i<arr.length){
if (arr[i]==val){
return i;
}
i++;
}
return -1;
}
}
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
// TODO: Replace examples and use TDD by writing your own tests
class SolutionTest {
@Test
void testSomething() {
int[] arr= {1,10,0,4,5,-6,7};
int val1=0;
int val2=-100;
int val3=100;
assertEquals(Solution.linear_search(arr,val1),2);
assertEquals(Solution.linear_search(arr,val2),-1);
assertEquals(Solution.linear_search(arr,val3),-1);
}
}
beHOLD! a recursive selection sort! will take tons of extra time and space for no good reason (seriously do not fork this,it is bad practice on all levels)
i should probably try to make this tail recursive lol
def isMin(val,arr):
match arr:
case []:
return True
case _:
return val<=arr[0] and isMin(val,arr[1:])
def findMin(i,arr):
match isMin(arr[i],arr):
case True:
return arr[i]
case _:
return findMin(i+1,arr)
def remove(target,arr):
match arr:
case []:
return []
case _:
return arr[1:] if target==arr[0] else [arr[0]]+remove(target,arr[1:])
def select(arr):
match arr:
case []:
return []
case _:
m=findMin(0,arr)
arr=remove(m,arr)
return [m]+select(arr)
import codewars_test as test
from solution import select
from random import randint
arr=[1,5,3,4,3,46,-100,-20,50]
arr2=[randint(-1000,1001) for _ in range(0,500)] #very very slow, also reaches a
#limit a little bit past 500
sortd=sorted(arr)
sortd2=sorted(arr2)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(select(arr), sortd)
test.assert_equals(select(arr2), sortd2)
Given an array of random numbers. Return the number of even numbers in the array.
function calculateEvenNumbers(array $numbers): int {
$result = [];
foreach ($numbers as $number) {
if ($number % 2 === 0) {
$result[] = $number;
}
}
return count($result);
}
<?php
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
public function testThatEvenNumbersAreCalculatedCorrectly() {
$this->assertEquals(0, calculateEvenNumbers([]));
$this->assertEquals(2, calculateEvenNumbers([5, 7, 2, 4, 9]));
$this->assertEquals(3, calculateEvenNumbers([60, 180, 99, 100, 101, 103]));
$this->assertEquals(0, calculateEvenNumbers([99, 9, 1, 21, 33, 77, 57, 33, 91, 111, 23451]));
$this->assertEquals(6, calculateEvenNumbers([10_000_000, 90_000, 700_000_000, 2, 70, 44]));
}
}
def counter():
n=-1
def closure():
nonlocal n
print(n)
n+=1
return closure
import codewars_test as test
# TODO Write tests
from solution import counter # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
c=counter()
c()
c()
c()
b=counter()
b()
b()
b()
a=counter()
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(1 + 0, 1)
Format in value
value with fixed decimal places numberOfPlaces
if it is a number, if it's not - return input as is.
function formatIfNumber(value, numberOfPlaces) {
return "";
}
// 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);
assert.strictEqual(formatIfNumber("word", 4), "word");
assert.strictEqual(formatIfNumber(8.141516, 4), 8.1415);
assert.strictEqual(formatIfNumber(2, 4), 2);
assert.strictEqual(formatIfNumber(15.34, 4), 15.34);
assert.strictEqual(formatIfNumber(15.34, 1), 15.3);
});
});