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.
Sometimes we buy something we may receive some change, so, how much?
#Examples:
getChange(4,10) => 6
getChange(4,100) => 96;
getChange(4.5,100) => 95.5;
getChange(3.5,5) => 1.5;
getChange(3.8,5) => 1.2;
###1 note this:youMoney > allPrice.
###2 Subtraction is not necessarily correct.
###3 Maybe you can use Math.
function getChange(allPrice,youMoney){
return Math.round(youMoney*1000 - allPrice*1000)/1000;
}
describe("Solution", function() {
it("should test for something", function() {
Test.assertEquals(getChange(4,10), 6);
Test.assertEquals(getChange(4,100), 96);
Test.assertEquals(getChange(4.5,100), 95.5);
Test.assertEquals(getChange(3.5,5), 1.5);
Test.assertEquals(getChange(3.8,5), 1.2);
// assert.strictEqual(1 + 1, 2);
});
});
We have n piles of apples, and we want to get them together.
Once a time we can combine two piles of apples with a and b apples seperately together, using a+b forces. We want to know the minimum forces we use to combine all piles of apples together.
Input:
apple(n,lst)
where lst contains n numbers representing the number of apples in each pile
#include<stdio.h>
#include<queue>
using namespace std;
int apple(int n,int* a)
{
priority_queue<int,vector<int>,greater<int> >q;
for(int i=0; i<n; i++)
q.push(a[i]);
int ans=0,tmp;
while(q.size()>=2)
{
tmp=0;
tmp+=q.top();
q.pop();
tmp+=q.top();
q.pop();
ans+=tmp;
q.push(tmp);
}
return ans;
}
// TODO: Replace examples and use TDD development by writing your own tests
Describe(any_group_name_you_want)
{
It(should_do_something)
{
int a[]={1,2,3,4};
Assert::That(apple(4,a), Equals(19));
}
};
The method should multiply parameters (a and b).
I hope that it won't be so difficult.
public class Multiplication
{
public int Multip(int a, int b)
{
return a * b;
}
}
namespace Solution {
using NUnit.Framework;
using System;
[TestFixture]
public class SolutionTest
{
[Test]
public void MyTest()
{
int a = 10;
int b = 5;
int expected = 50;
Multiplication test = new Multiplication();
int actural = test.Multip(a, b);
Assert.AreEqual(expected, actural);
}
}
}
This is a first experiment of mine in generating primes. Theoretically, with enough calculating power and storage space you could find primes indefinitely. I cribbed some of the guts from another work and justled them around a bit. Advice welcome.
def primemaker(x):
primes = []
isprime = True
for possibleprimes in range(2,x):
for n in range(2,possibleprimes):
if possibleprimes % num == 0:
isprime = False
if isprime:
primes.append(possibleprimes)
print(primes)
# 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
var foo* = 0
suite "suite":
test "test":
check(foo == 1)
check(foo == 2)
;
#lang racket
(require rackunit codewars/rackunit)
(define-check (nested-info-check)
(define infos
(list (make-check-info 'foo "foo")
(make-check-info 'bar "bar")))
(with-check-info (['nested (nested-info infos)]) (fail-check)))
(define a-test-suite
(test-suite
"This is a test suite"
(check-eq? 1 1)
(test-case "This is a success test case"
(check-eq? 1 1)
(check-equal? '(10 "a string") '(10 "a string")))
(test-case "This is a failed case"
(check-eq? 1 "string\nwith newline" "I am some message!")
(check-pred even? 3))
(test-suite
"More test cases"
(nested-info-check)
(test-case "This is a test case for test printing to console"
(print 'yes))
(test-case "Here will be an error!"
(/ 1 0)))))
;; (run-tests a-test-suite)
;; (run-tests a-test-suite #:mode 'simple)
(run-tests a-test-suite #:mode 'all)
;; (run-tests a-test-suite #:mode '(name params location actual expected))
Find a way to make the positive number negative!
function neg(number) {
return -(number);
}
// 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:
Test.assertEquals(neg(1), -1,)
e
e
// 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(1 + 1, 2);
// assert.strictEqual(1 + 1, 2);
});
});
f=_=>{_.sort();return _[0]!=_[1]?_[0]:_[_.length-1]==_[_.length-2]?'Error':_[_.length-1]};
describe("Solution", function() {
it("simple", function() {
Test.assertEquals(f([1,1,1,1,1,1,1,4,1,1]),4);
Test.assertEquals(f(['AD','AD','Ad','AD']),'Ad');
Test.assertSimilar(f(['null','nulll','null']),'nulll');
});
it("wrong", function() {
Test.assertEquals(f([undefined,undefined,undefined,undefined]),'Error');
});
});
Consider a syntax named with-break
,
(with-break
(define x 1)
(break 2)
x)
within its scope,you can use function break
to jump out.
This example returns 2 because break
stops the current computation.
You may approach this by using functions like call/cc
,call/ec
,shift
,reset
.
#lang racket
(require racket/control)
(provide with-break break)
(define break-parameter (make-parameter (λ (val)
(error "you can't use break without with-break"))))
(define break
(λ (val)
((break-parameter) val)))
(define-syntax-rule (with-break bodies ...)
(call/ec (λ (exit)
(parameterize ([break-parameter exit])
bodies ...)
)))
#lang racket
(require "solution.rkt")
(require rackunit
codewars/rackunit)
;; codewars/rackunit provides `run-tests`.
;; See RackUnit documentation. https://docs.racket-lang.org/rackunit
(run-tests
(test-suite "example"
(test-case "simple example 1"
(check-equal? (with-break
(define x 1)
(break 2)
x) 2))
(test-case "simple example 2"
(check-equal? (with-break
1)
1))
(test-case "harder example"
(check-equal? (let ([f (λ () (break 99))])
(with-break
(f)
22))
99))
(test-suite "hard tests"
(test-case "hard test 1"
(check-exn
exn:fail?
(thunk (with-break
(break 1))
(break 2)))
)
(test-case "hard test 2"
(check-exn
(lambda (ex)
(and (exn:fail? ex)
(equal? (exn-message ex) "you can't use break without with-break")))
(thunk (with-break
(break 1))
(break 2)))
))
))