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.
def mul(): sum=0 for i in range(1, 1000): if(i % 3 == 0 or i % 5 == 0): sum += i return sum
- def mul():
- sum=0
for i in range(1001):if i>0:if(i%3==0 or i%5==0):sum=sum+1return sum- for i in range(1, 1000):
- if(i % 3 == 0 or i % 5 == 0):
- sum += i
- return sum
test.assert_equals(mul(), 233168)
- test.assert_equals(mul(), 233168)
function func(N, point) { return funcHelper(N, point, []) } function funcHelper(N, x, arr) { return N === 0 ? arr : funcHelper(N - 1, x - 1, [...arr, Math.abs(x)]) }
- function func(N, point) {
let start = 0; // starting position of arraylet clonePoint = point; // clone for point to start counting from that number at begining of arraylet arr = [...Array(N).keys()] // generate array and fill with 0 to 10if(!(point > N)) {arr.forEach((o, index) => {index < point ? arr[index] = clonePoint-- : arr[index] = start++;});return arr;}return [];- return funcHelper(N, point, [])
- }
- function funcHelper(N, x, arr) {
- return N === 0 ? arr : funcHelper(N - 1, x - 1, [...arr, Math.abs(x)])
- }
PEP 8 - Naming Conventions - Function Names:
Function names should be lowercase, with words separated by underscores as necessary to improve readability.
This naming style is commonly known as snake_case
.
Furthermore, the variable assignment in the previous Kumite is not required; the computed result can be returned immediately.
Finally, as per the Python Test Reference in the official Codewars Docs, the order of arguments for Test.assert_equals
should be actual, expected
instead of the other way round.
from itertools import permutations def sequence_permutation(t, n): return list(permutations(t, n))
- from itertools import permutations
def SequencePermutation(plenty, count):ret = list(permutations(plenty, count))return ret- def sequence_permutation(t, n):
- return list(permutations(t, n))
Test.describe("sequence_permutation") Test.it("should correct calculate for permutations with three by three") sq_per_master = sequence_permutation(('a','b','c'), 3) Test.assert_equals(list(sq_per_master[0]), ['a', 'b', 'c']) Test.assert_equals(list(sq_per_master[1]), ['a', 'c', 'b']) Test.assert_equals(list(sq_per_master[4]), ['c', 'a', 'b']) Test.it("should correct calculate for permutations with one item") sq_per_master = sequence_permutation(('a','b','c'), 1) Test.assert_equals(list(sq_per_master[0]), ['a']) Test.assert_equals(list(sq_per_master[1]), ['b']) Test.assert_equals(list(sq_per_master[2]), ['c']) Test.it("should correct calculate for permutations with two items") sq_per_master = sequence_permutation(('a','b','c'), 2) Test.assert_equals(list(sq_per_master[0]), ['a', 'b']) Test.assert_equals(list(sq_per_master[1]), ['a', 'c']) Test.assert_equals(list(sq_per_master[4]), ['c', 'a'])
Test.describe("SequencePermutation")- Test.describe("sequence_permutation")
- Test.it("should correct calculate for permutations with three by three")
- sq_per_master = sequence_permutation(('a','b','c'), 3)
- Test.assert_equals(list(sq_per_master[0]), ['a', 'b', 'c'])
- Test.assert_equals(list(sq_per_master[1]), ['a', 'c', 'b'])
- Test.assert_equals(list(sq_per_master[4]), ['c', 'a', 'b'])
Test.describe("should correct calculate for permutations with three by three")sq_per_master = SequencePermutation(('a','b','c'), 3)Test.assert_equals(['a', 'b', 'c'], list(sq_per_master[0]))Test.assert_equals(['a', 'c', 'b'], list(sq_per_master[1]))Test.assert_equals(['c', 'a', 'b'], list(sq_per_master[4]))- Test.it("should correct calculate for permutations with one item")
- sq_per_master = sequence_permutation(('a','b','c'), 1)
- Test.assert_equals(list(sq_per_master[0]), ['a'])
- Test.assert_equals(list(sq_per_master[1]), ['b'])
- Test.assert_equals(list(sq_per_master[2]), ['c'])
Test.describe("should correct calculate for permutations with one item")sq_per_master = SequencePermutation(('a','b','c'), 1)Test.assert_equals(['a'], list(sq_per_master[0]))Test.assert_equals(['b'], list(sq_per_master[1]))Test.assert_equals(['c'], list(sq_per_master[2]))Test.describe("should correct calculate for permutations with two items")sq_per_master = SequencePermutation(('a','b','c'), 2)Test.assert_equals(['a', 'b'], list(sq_per_master[0]))Test.assert_equals(['a', 'c'], list(sq_per_master[1]))Test.assert_equals(['c', 'a'], list(sq_per_master[4]))- Test.it("should correct calculate for permutations with two items")
- sq_per_master = sequence_permutation(('a','b','c'), 2)
- Test.assert_equals(list(sq_per_master[0]), ['a', 'b'])
- Test.assert_equals(list(sq_per_master[1]), ['a', 'c'])
- Test.assert_equals(list(sq_per_master[4]), ['c', 'a'])
Hello Brainf**k with "default arguments"
The last two BF programs I published would simply print a weirdly formatted string if the input is empty (or not provided), like so: "Hello "
/"Hello !"
. Obviously, that isn't desirable behavior so I refactored my program to print "Hello World!"
in case of empty input.
++++++++++[>+++++++>++++++++++>+++++++++++>+++<<<<-]>++.>+.>--..+++.>++.>->,[.<[+]>,]<[[+]++++++++++[>+++++++++>+++++++++++>++++++++++<<<-]>---.>+.+++.------.>.<<<]<+.
++++++++++[>+++++++>++++++++++>+++++++++++>+++<<<<-]>++.>+.>--..+++.>++.>,[.,]<+.- +++++++++++[>+++++++>++++++++++>+++++++++++>+++<<<<-]>++.>+.>--..+++.>++.>->,[.<[+]>,]<[[+]++++++++++[>+++++++++>+++++++++++>++++++++++<<<-]>---.>+.+++.------.>.<<<]<+.
Test.describe('The BF greeting program (with input)', function () { Test.it('should work with input "Brainf**k"', function () { Test.assertEquals(runBF('Brainf**k' + EOF), 'Hello Brainf**k!'); }); Test.it('should work with a range of other inputs', function () { Test.assertEquals(runBF('JavaScript' + EOF), 'Hello JavaScript!'); Test.assertEquals(runBF('Node 8' + EOF), 'Hello Node 8!'); Test.assertEquals(runBF('Codewars' + EOF), 'Hello Codewars!'); Test.assertEquals(runBF('@jhoffner' + EOF), 'Hello @jhoffner!'); Test.assertEquals(runBF('@donaldsebleung' + EOF), 'Hello @donaldsebleung!'); }); Test.it('should have a "default argument" of "World"', function () { Test.assertEquals(runBF(EOF), 'Hello World!'); }); Test.it('should work properly if "World" is passed in anyway', function () { Test.assertEquals(runBF('World' + EOF), 'Hello World!'); }); });
- Test.describe('The BF greeting program (with input)', function () {
- Test.it('should work with input "Brainf**k"', function () {
- Test.assertEquals(runBF('Brainf**k' + EOF), 'Hello Brainf**k!');
- });
- Test.it('should work with a range of other inputs', function () {
- Test.assertEquals(runBF('JavaScript' + EOF), 'Hello JavaScript!');
- Test.assertEquals(runBF('Node 8' + EOF), 'Hello Node 8!');
- Test.assertEquals(runBF('Codewars' + EOF), 'Hello Codewars!');
- Test.assertEquals(runBF('@jhoffner' + EOF), 'Hello @jhoffner!');
- Test.assertEquals(runBF('@donaldsebleung' + EOF), 'Hello @donaldsebleung!');
- });
- Test.it('should have a "default argument" of "World"', function () {
- Test.assertEquals(runBF(EOF), 'Hello World!');
- });
- Test.it('should work properly if "World" is passed in anyway', function () {
- Test.assertEquals(runBF('World' + EOF), 'Hello World!');
- });
- });