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.
It's binarySearch implementation on JS. This returns the index number that contains the value. If the value is not in the array, it will return -1
function binarySearch(arr, el) {
let left = -1;
let right = arr.length;
while (right - left > 1) {
const mid = Math.floor((left + right) / 2);
if (arr[mid] === el) {
return mid;
}
if (arr[mid] > el) {
right = mid;
} else {
left = mid;
}
}
return -1;
}
const chai = require("chai");
const assert = chai.assert;
describe("Solution", function() {
it("return index of searching element", function() {
assert.strictEqual(binarySearch([1, 2, 3, 4, 5, 6, 7], 4), 3);
assert.strictEqual(binarySearch([1, 2, 3, 4, 5, 6, 7], 2), 1);
assert.strictEqual(binarySearch([1, 2, 3, 4, 5, 6, 7], 8), -1);
});
});
Hello Everyone!
In this Kata/Kumite we will work with strings!!
You have to find all chars indexes passed by parameter in a string
and replace them with the index parameter with pad left '0'.
EXAMPLE 1:
sValueReplacer("9182 7391238 91$$$$", 3, '$');
RESULT 1:
9182 7391238 910003
EXAMPLE 2:
sValueReplacer("The counter is ---", 11, '-');
RESULT 2:
"The counter is 011"
using System;
using System.Linq;
using System.Collections.Generic;
public class Test{
static void Main(){
Console.WriteLine(Replacer.sValueReplacer("0000##81#059671####=1811", 3, '#'));
}
}
public class Replacer{
public static string sValueReplacer(string source, int index, char char_to_replace)
{
string res = source;
try
{
if (!string.IsNullOrEmpty(char_to_replace.ToString()))
{
if (res.Contains(char_to_replace.ToString()))
{
// Get ALL Indexes position of character
var Indexes = GetIndexes(res, char_to_replace.ToString());
int max = GetMaxValue(Indexes.Count);
while (index >= max)
{
index -= max;
}
var new_value = index.ToString().PadLeft(Indexes.Count, '0');
for (int i = 0; i < Indexes.Count; i++)
{
res = res.Remove(Indexes[i], 1).Insert(Indexes[i], new_value[i].ToString());
}
}
}
}
catch (Exception)
{
res = source;
}
return res;
}
private static List<int> GetIndexes(string mainString, string toFind)
{
var Indexes = new List<int>();
for (int i = mainString.IndexOf(toFind); i > -1; i = mainString.IndexOf(toFind, i + 1))
{
// for loop end when i=-1 (line.counter not found)
Indexes.Add(i);
}
return Indexes;
}
private static int GetMaxValue(int numIndexes)
{
int max = 0;
for (int i = 0; i < numIndexes; i++)
{
if (i == 0)
max = 9;
else
max = max * 10 + 9;
}
return max;
}
}
# 90 degrees clockwise matrix rotate
def rotate(m):
return list(zip(*m))[::-1]
import codewars_test as test
actual = [(1,2,3),
(4,5,6),
(7,8,9)]
expected = [(3,6,9),
(2,5,8),
(1,4,7)]
@test.it("test 3x3 matrix")
def test():
test.assert_equals(rotate(actual), expected)
Create a function, that takes string as its only argument and yields rot13-encoded string. Only standard latin letters must be affected, avoid touching other characters and whitespaces.
defmodule Rot13 do
def rotate({k, v}) do
cond do
v in ?A..?M ->
k + 13
v in ?N..?Z ->
k - 13
true ->
k
end
end
def encode(str) do
List.zip([
str
|> String.to_charlist(),
str
|> String.upcase()
|> String.to_charlist()
])
|> Enum.map(&rotate/1)
|> List.to_string()
end
end
# TODO: Replace examples and use TDD by writing your own tests
defmodule TestSolution do
use ExUnit.Case
import Rot13, only: [encode: 1]
test "some test description" do
assert encode("NOWHERE abjurer") == "ABJURER nowhere"
assert encode(" stuff ") == " fghss "
assert encode("123 mirë u pafshim абв") == "123 zveë h cnsfuvz абв"
end
end
The function take a number and checks if it is in the Fibonnacci Sequence. If it is return "yes", else return "no".
Fibonnacci sequence explained:
starts with 0 and 1. It adds the two previous numbers to get the next one, then continues the pattern.
Some of the beginning sequence: 0,1,1,2,3,5,8,13,21...
function isSquare(x) {
// code goes here
let sq = parseInt(Math.sqrt(x));
return check = (sq * sq == x)
}
function FibonacciChecker(num){
return (isSquare(5 * num * num + 4) || isSquare(5 * num * num -4)) ? "yes" : "no";
}
// 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() {
assert(FibonacciChecker(5), "yes");
assert(FibonacciChecker(6), "no");
});
});
In this kata you are restructuring given object with agregated properties by underscore into nested object
Sample transformation :
const before = {
a_b_c : 'value'
}
restructured into:
const after = {
a : {
b: {
c: 'value'
}
}
}
export function transform(obj: any) {
const _RegEx = new RegExp(/_/);
const underscoredProp = Object.keys(obj).find(key =>
_RegEx.test(key)) || '';
const value = obj[underscoredProp];
const propertList = underscoredProp.split('_').reverse();
let toAdd = {};
propertList.map((prop,index) => {
toAdd = index==0 ?{[prop]:value} : {[prop]:toAdd}
})
return toAdd;
}
// See https://www.chaijs.com for how to use Chai.
import { assert } from "chai";
import { transform } from "./solution";
// TODO Add your tests here
describe("example", function() {
const before = { a_b_c : 'value' }
const before_2 = { a_b_c : 'value', d:'value_d' }
const after = {
a : {
b: {
c: 'value'
}
}
}
const after_2 = {
a : {
b: {
c: 'value'
}
},
d:'value_d'
}
it("test", function() {
assert.deepEqual(transform(before), after);
assert.deepEqual(transform(before_2), after_2);
});
});
const {execSync} = require('child_process');
execSync(`echo '{"foo": "bar"}' >file.json`);
console.log(require('./file.json'));
execSync(`echo '{"baz": "qux"}' >file.json`);
console.log(require('./file.json')); // cached
ALLOW FRIENDS TO ADD ME THROUGH KUMITE
#include<iostream>
std::string dfescribe(std::string){
};
// TODO: Replace examples and use TDD by writing your own tests
#include<iostream>
dfescribe("any_group_name_you_want");
/*
Description:
"7777...8?!??!", exclaimed Bob, "I missed it again! Argh!" Every time there's an interesting number coming up, he notices and then promptly forgets. Who doesn't like catching those one-off interesting mileage numbers?
Let's make it so Bob never misses another interesting number. We've hacked into his car's computer, and we have a box hooked up that reads mileage numbers. We've got a box glued to his dash that lights up yellow or green depending on whether it receives a 1 or a 2 (respectively).
It's up to you, intrepid warrior, to glue the parts together. Write the function that parses the mileage number input, and returns a 2 if the number is "interesting" (see below), a 1 if an interesting number occurs within the next two miles, or a 0 if the number is not interesting.
Note: In Haskell, we use No, Almost and Yes instead of 0, 1 and 2.
"Interesting" Numbers
Interesting numbers are 3-or-more digit numbers that meet one or more of the following criteria:
Any digit followed by all zeros: 100, 90000
Every digit is the same number: 1111
The digits are sequential, incementing†: 1234
The digits are sequential, decrementing‡: 4321
The digits are a palindrome: 1221 or 73837
The digits match one of the values in the awesomePhrases array
† For incrementing sequences, 0 should come after 9, and not before 1, as in 7890.
‡ For decrementing sequences, 0 should come after 1, and not before 9, as in 3210.
So, you should expect these inputs and outputs:
// "boring" numbers
isInteresting(3, [1337, 256]); // 0
isInteresting(3236, [1337, 256]); // 0
// progress as we near an "interesting" number
isInteresting(11207, []); // 0
isInteresting(11208, []); // 0
isInteresting(11209, []); // 1
isInteresting(11210, []); // 1
isInteresting(11211, []); // 2
// nearing a provided "awesome phrase"
isInteresting(1335, [1337, 256]); // 1
isInteresting(1336, [1337, 256]); // 1
isInteresting(1337, [1337, 256]); // 2
Error Checking
A number is only interesting if it is greater than 99!
Input will always be an integer greater than 0, and less than 1,000,000,000.
The awesomePhrases array will always be provided, and will always be an array, but may be empty. (Not everyone thinks numbers spell funny words...)
You should only ever output 0, 1, or 2.
*/
const chars = n => n.toString().split("");
const match = s => n => new RegExp(n).test(s);
const tests = [
match("1234567890"), // incremental
match("9876543210"), // decremental
n => /^\d[0]+$/.test(n), // all zeroes
n =>
n ==
chars(n)
.reverse()
.join(""), // palindrome
n => [...new Set(chars(n))].length === 1 // repeated
];
const test = (n, xs) =>
n > 99 && (xs.indexOf(n) > -1 || tests.map(t => t(n)).some(x => !!x));
const isInteresting = (n, xs) =>
test(n, xs) ? 2 : +(test(n + 1, xs) || test(n + 2, xs));
// 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);
});
});
With the power of regex it becomes easy to tell if your string has even length!
class StringParity {
public static boolean isEvenLength(String str) {
return str.replaceAll("(?s)..", "").isEmpty(); // (?s) enables DOTALL
}
}
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class SolutionTest {
@Test
void testSomething() {
assertEquals(true, StringParity.isEvenLength("even"));
assertEquals(false, StringParity.isEvenLength("odd"));
assertEquals(true, StringParity.isEvenLength(""));
assertEquals(false, StringParity.isEvenLength("Instant Noodles"));
assertEquals(true, StringParity.isEvenLength("\n\n"));
}
}