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.
main.cpp:10:10: error: always_inline function '_mm256_add_pd' requires target feature 'avx', but would be inlined into function 'add' that is compiled without support for 'avx'
return _mm256_add_pd(xs, ys);
#include <immintrin.h>
using v4d = double __attribute__((__vector_size__(32)));
v4d add(v4d xs, v4d ys) {
return _mm256_add_pd(xs, ys);
}
Describe(add_function) {
It(should_add_vectors_of_doubles) {
auto xs = v4d{1, 2, 3, 4}, ys = v4d{10, 20, 30, 40};
auto e = xs + ys, a = add(xs, ys);
Assert::That(a[0], Equals(e[0]));
}
};
solution.c:6:10: error: always_inline function '_mm256_add_pd' requires target feature 'avx', but would be inlined into function 'add' that is compiled without support for 'avx'
return _mm256_add_pd(xs, ys);
#include <immintrin.h>
typedef double v4d __attribute__((__vector_size__(32)));
v4d add(v4d xs, v4d ys) {
return _mm256_add_pd(xs, ys);
}
#include <criterion/criterion.h>
typedef double v4d __attribute__((__vector_size__(32)));
v4d add(v4d xs, v4d ys);
Test(add_function, should_add_vectors_of_doubles) {
v4d xs = (v4d){1, 2, 3, 4}, ys = (v4d){10, 20, 30, 40};
v4d e = xs + ys, a = add(xs, ys);
cr_assert_eq(a[0], e[0]);
}
Given a string S of length N, the task is to find the length of the longest palindromic substring from a given string.
Examples:
Input: S = “abcbab”
Output: 5
Explanation:
string “abcba” is the longest substring that is a palindrome which is of length 5.
Input: S = “abcdaa”
Output: 2
Explanation:
string “aa” is the longest substring that is a palindrome which is of length 2.
Note: If the string is empty or None or null then just return 0.do not try to convert the string to lowercase
def length_longest_palindrome(string):
n = len(string)
if n == 0:
return 0
maxlen = 1
table = [[False for i in range(n)]for j in range(n)]
for i in range(n):
table[i][i] = True
start = 0
for i in range(n-1):
if string[i] == string[i+1]:
table[i][i+1] = True
start = i
maxlen = 2
for k in range(3,n+1):
for i in range(n-k+1):
j = i + k - 1
if table[i+1][j-1] and string[i] == string[j]:
table[i][j] = True
if k > maxlen:
start = i
maxlen = k
return maxlen
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(length_longest_palindrome(''),0)
test.assert_equals(length_longest_palindrome('a'),1)
test.assert_equals(length_longest_palindrome('aaabbaa'),6)
test.assert_equals(length_longest_palindrome('Hannah'),4)
test.assert_equals(length_longest_palindrome('geeks'),2)
test.assert_equals(length_longest_palindrome('forgeeksskeegfor'),10)
test.assert_equals(length_longest_palindrome('aab'),2)
test.assert_equals(length_longest_palindrome('Abbas'),2)
Given an array of positive integers representing coin denominations and a single non-negative integer n.
representing a target amount of money, write a function that returns the smallest number of coins needed to
make change for (to sum up to) that target amount using the given coin denominations.
Example:
sample Input
n = 7
denoms = [1,5,10]
output = 3//2x1+1x5
time = O(nd),space = O(n).
where n is target amount and d is number of coin denominations
Note: you have access to an unlimited amount of coins.In other words,if denominations are [1,5,10],you have access to unlimited amount of 1s,5s and 10s
If it's impossible to make change for target amount return -1
def minNumberOfCoinsForChange(n, denoms):
numOfCoins = [float('inf') for amount in range(n+1)]
numOfCoins[0] = 0
for denom in denoms:
for amount in range(len(numOfCoins)):
if denom <= amount:
numOfCoins[amount] = min(numOfCoins[amount],1+numOfCoins[amount - denom])
return numOfCoins[n] if numOfCoins[n] != float('inf') else -1
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(minNumberOfCoinsForChange(7,[1,5,10]),3)
test.assert_equals(minNumberOfCoinsForChange(7,[1,10,5]),3)
test.assert_equals(minNumberOfCoinsForChange(7,[5,1,10]),3)
test.assert_equals(minNumberOfCoinsForChange(0,[1,2,3]),0)
test.assert_equals(minNumberOfCoinsForChange(3,[2,1]),2)
test.assert_equals(minNumberOfCoinsForChange(4,[1,5,10]),4)
test.assert_equals(minNumberOfCoinsForChange(10,[1,5,10]),1)
test.assert_equals(minNumberOfCoinsForChange(24,[1,5,10]),6)
test.assert_equals(minNumberOfCoinsForChange(9,[3,5]),3)
test.assert_equals(minNumberOfCoinsForChange(10,[1,3,4]),3)
test.it("good testcases")
test.assert_equals(minNumberOfCoinsForChange(135,[39, 45, 130, 40, 4, 1, 60, 75]),2)
test.assert_equals(minNumberOfCoinsForChange(135, [39, 45, 130, 40, 4, 1]),3)
given that you have:
stringObject = `{
\"a\":\"false\",
\"b\":\"33\",
\"c\":\"hi i'm C!\",
\"d\":\"{
\\\"d1\\\":\\\"4.5\\\",
\\\"d2\\\":\\\"Yo D2 here\\\"
}\"
}`
make it deeply primitive as such:
resultObject = {
a: false,
b: 33,
c: "hi i'm C!",
d:{
d1:4.5,
d2:"Yo D2 here"
}
}
function toPrimitiveDeep(stringObject){
let result
try{
result = JSON.parse(stringObject);
}catch (e){
return stringObject
}
if(typeof result !== 'object') return result
let keys = Object.keys(result)
keys.forEach((key)=>{
result[key] = toPrimitiveDeep(result[key])
})
return result
}
// Since Node 10, we"re using Mocha.
// You can use `chai` for assertions.
// 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");
const chai = require('chai')
const assert = chai.assert
const stgfy= JSON.stringify
describe('Solution', function () {
it('should test for something', function () {
const obj1 = `{"a":"false","b":"33","c":"hi i\'m C!","d":"{\\"d1\\":\\"4.5\\",\\"d2\\":\\"Yo D2 here\\"}"}`
assert.strictEqual(
stgfy(toPrimitiveDeep(obj1)),
stgfy({
a: false,
b: 33,
c: "hi i'm C!",
d: {
d1: 4.5,
d2: 'Yo D2 here',
},
}),
)
}),
it('should return the string when string is passed',()=>{
let aString = 'a string'
assert.strictEqual(toPrimitiveDeep(aString),aString)
}),
it('should return boolean when get string as "true" or "false"',()=>{
let thaBoolean = Math.random()<0.45
assert.strictEqual(toPrimitiveDeep(thaBoolean), thaBoolean)
}),
it('should return a deep object with a value diferent of a string when it can be interpreted as number or boolean', ()=>{
let thaBoolean = Math.random()<0.45
let thaNumba = Math.random() *100 %10
let answer = {
a:thaBoolean,
b:{
ba:thaNumba,
bb:{
bba:thaBoolean,
bbb:thaNumba
}
}
}
let question = stgfy({
a:thaBoolean.toString(),
b:stgfy({
ba:thaNumba.toString(),
bb:stgfy({
bba:thaBoolean.toString(),
bbb:thaNumba.toString()
})
})
})
console.log(question, answer)
assert.strictEqual(stgfy(toPrimitiveDeep(question)), stgfy(answer))
})
})
denis
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# 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)
Just checking whether PowerShell submissions on Codewars are executed in a Linux (most likely), Windows (less likely) or macOS (probably not) environment.
if ($IsWindows) {
Write-Host "Windows"
} elseif ($IsMacOS) {
Write-Host "macOS"
} elseif ($IsLinux) {
Write-Host "Linux"
} else {
Write-Host "(unknown)"
}
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);
});
});
// 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);
});
});
Your boss give you a task to format some integer numbers like this:
123456789
-> 123,456,789
So, you should write a function f
which recieves a integer number and returns a string which every 3 consecutive digits are splitted with ,
symbol from left to right.
def f(n):
G = 3
s = str(n)
r = len(s) % G
def make(s):
if r:
yield s[:r]
for i in range(r, len(s), G):
yield s[i:i+G]
return ','.join(make(s))
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
test.assert_equals(f(100), '100')
test.assert_equals(f(1000), '1,000')
test.assert_equals(f(12345), '12,345')
test.assert_equals(f(123456789), '123,456,789')
test.assert_equals(f(10000000000), '10,000,000,000')
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(1 + 1, 2)
reverse the string passed as an arg and return the result
function revstr(str) {
i = str.length; newstr = "";
while (i > 0) {
newstr += str[i - 1]; i--;
}
return newstr;
}
const chai = require("chai");
const assert = chai.assert;
describe("Solution", function() {
it("return reversed", function() {
assert.strictEqual(revstr("ok hello"), "olleh ko");
});
});