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.
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)))
))
))
let foo x = 0
module Tests = struct
open OUnit
let suite =
let test_with input expected =
let format_input = Printf.sprintf "x = %d" in
assert_equal expected (foo input) ~msg:(format_input input) ~printer:string_of_int
in [
"foo" >:: (fun _ ->
test_with 1 1;
test_with 2 2;
);
]
end
Using your programming language of choice from the drop-down, write a function that takes a string and returns the count of instances of the letter "a" in the string.
The comparison should be case-insensitive, i.e. both "a" and "A" should count.
For example, "abcABC" should return 2.
function count(string) {
}
// 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() {
assert.strictEqual(count('abcABC'), 2);
});
});
An algorithm best suited for the calculation of very large fibonnaci numbers, but works very well for simply populating a list or dictionary with these values.
The algorithm here uses a dictionary (which has O(1) access time) to hold values used by further calls. The implementation has a logarithmic time using an identity that allows us to calculate fib(2n) efficently from fib(n)
Uses the binary and operator because it is much faster in calculating if a number is odd or even.
If you wish to work with fibonnaci numbers past around the 4 millionth, I sincerely suggest you use a different language, as python has a hard time storing values much larger than this.
If you wish to use this with fibonnaci numbers that are modulo'd by some constant (as I used this for in problem 422 of project euler) then you may use it up to and beyond the 1st quadrillionth fibbonacci quiet easily
F = {0: 0, 1: 1, 2: 1}
def fib(n):
"""
Return the nth Fibonacci number in O(log(n)) time
"""
if n in F:
return F[n]
f1 = fib(n // 2 + 1)
f2 = fib((n - 1) // 2)
F[n] = (f1 * f1 + f2 * f2 if n & 1 else f1 * f1 - f2 * f2)
return F[n]
test.assert_equals(fib(10),55)
test.assert_equals(fib(6), 8)
test.assert_equals(fib(1000), 43466557686937456435688527675040625802564660517371780402481729089536555417949051890403879840079255169295922593080322634775209689623239873322471161642996440906533187938298969649928516003704476137795166849228875)
This function takes an integer as a Parameter and returns a list of factors for that number in ascending order. It uses a set and an optimized loop for preventing repeated values.
As far as I can tell, it works as well with large numbers. For some reason the code does not run on this platform.
def Factorize(num):
"""Factorizes an Integer"""
# set because values are unique
factset = set()
try:
num = int(num)
except:
raise Exception("Please Enter an Integer")
if num <= 0:
raise Exception("Entered Number must be grater than 0")
for i in range(1, int(num/2-1)):
result = num/i
if num % i == 0:
factset.add(i)
factset.add(int(result))
return sorted(list(factset))
num = 10246
# f-strings for formatting in a more pythonic way
print(f"Input = {num}")
print("Factors: ", end="")
# completely pointless, for aesthetics :)
print(f"{', '.join([str(i) for i in Factorize(num)])}")
# Output should be: 1, 2, 47, 94, 109, 218, 5123, 10246
# 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