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.
const main = () => { const links = [ 'https://www.uol', 'https://www.bol.com.br', 'https://www.uol', 'https://noticias.uol.com.br', 'https://www.bol.com.br', ]; // converter para ES6 function uniqueLinks (links){ return uniqueLinks.length; } };
- const main = () => {
- const links = [
- 'https://www.uol',
- 'https://www.bol.com.br',
- 'https://www.uol',
- 'https://noticias.uol.com.br',
- 'https://www.bol.com.br',
- ];
- // converter para ES6
const uniqueLinks = new Set(links);return uniqueLinks.length;- function uniqueLinks (links){
- return uniqueLinks.length;
- }
- };
Task
Complete the method which accepts an integer value
and returns a string of numbers delimited by either -
if the value is positive or +
if the value is negative.
Examples
0 -> ""
1 -> "1"
5 -> "1-22-333-4444-55555"
-1 -> "1"
-5 -> "1+22+333+4444+55555"
import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; class Solution { public static String numberOfNumbers(final int value) { if (value == 0) { return ""; } final String delimiter = value > 0 ? "-" : "+"; return IntStream.rangeClosed(1, Math.abs(value)) .mapToObj(n -> new String(new char[n]).replace("\0", String.valueOf(n))) .collect(Collectors.joining(delimiter)); } }
class Solution {public static String numberOfNumbers(int value) {StringBuilder finalWord = new StringBuilder();int j = 0;String sign = value < 0 ? "+" : "-";if (value == 0) return "";if (value < 0) value *=-1;- import java.util.stream.Collectors;
- import java.util.stream.IntStream;
- import java.util.stream.Stream;
for (int i = 1; i <= value; ++i) {j = i;while (j > 0) {finalWord.append(i);--j;}finalWord.append(sign);}return finalWord.deleteCharAt(finalWord.length() - 1).toString();}- class Solution {
- public static String numberOfNumbers(final int value) {
- if (value == 0) {
- return "";
- }
- final String delimiter = value > 0 ? "-" : "+";
- return IntStream.rangeClosed(1, Math.abs(value))
- .mapToObj(n -> new String(new char[n]).replace("\0", String.valueOf(n)))
- .collect(Collectors.joining(delimiter));
- }
- }
import org.junit.Test; import static org.junit.Assert.assertEquals; import org.junit.runners.JUnit4; public class SolutionTest { @Test public void testWhenValueIsZero() { assertEquals("", Solution.numberOfNumbers(0)); } @Test public void testPositiveValues() { assertEquals("1", Solution.numberOfNumbers(1)); assertEquals("1-22", Solution.numberOfNumbers(2)); assertEquals("1-22-333", Solution.numberOfNumbers(3)); assertEquals("1-22-333-4444", Solution.numberOfNumbers(4)); assertEquals("1-22-333-4444-55555", Solution.numberOfNumbers(5)); } @Test public void testNegativeValues() { assertEquals("1", Solution.numberOfNumbers(-1)); assertEquals("1+22", Solution.numberOfNumbers(-2)); assertEquals("1+22+333", Solution.numberOfNumbers(-3)); assertEquals("1+22+333+4444", Solution.numberOfNumbers(-4)); assertEquals("1+22+333+4444+55555", Solution.numberOfNumbers(-5)); } @Test public void testWithDoubleDigitValue() { assertEquals("1-22-333-4444-55555-666666-7777777-88888888-999999999-10101010101010101010", Solution.numberOfNumbers(10)); } }
- import org.junit.Test;
- import static org.junit.Assert.assertEquals;
- import org.junit.runners.JUnit4;
// TODO: Replace examples and use TDD development by writing your own tests- public class SolutionTest {
- @Test
public void testThree() {assertEquals("1-22-333", Solution.numberOfNumbers(3));- public void testWhenValueIsZero() {
- assertEquals("", Solution.numberOfNumbers(0));
- }
- @Test
public void testOne() {- public void testPositiveValues() {
- assertEquals("1", Solution.numberOfNumbers(1));
- assertEquals("1-22", Solution.numberOfNumbers(2));
- assertEquals("1-22-333", Solution.numberOfNumbers(3));
- assertEquals("1-22-333-4444", Solution.numberOfNumbers(4));
- assertEquals("1-22-333-4444-55555", Solution.numberOfNumbers(5));
- }
- @Test
public void testNone() {- public void testNegativeValues() {
- assertEquals("1", Solution.numberOfNumbers(-1));
}@Testpublic void testNFive() {- assertEquals("1+22", Solution.numberOfNumbers(-2));
- assertEquals("1+22+333", Solution.numberOfNumbers(-3));
- assertEquals("1+22+333+4444", Solution.numberOfNumbers(-4));
- assertEquals("1+22+333+4444+55555", Solution.numberOfNumbers(-5));
- }
@Testpublic void testZero() {assertEquals("", Solution.numberOfNumbers(0));}@Testpublic void testFive() {assertEquals("1-22-333-4444-55555", Solution.numberOfNumbers(5));}- @Test
public void testTen() {- public void testWithDoubleDigitValue() {
- assertEquals("1-22-333-4444-55555-666666-7777777-88888888-999999999-10101010101010101010", Solution.numberOfNumbers(10));
- }
- }
function alphabetPosition(text) { return text.toLowerCase().match(/[a-z]/g) != null ? text.toLowerCase().match(/[a-z]/g).map((l) => l.charCodeAt(0)-96).join(' ') : ''; }
- function alphabetPosition(text) {
let obj = {"a": 1, "b": 2, "c": 3, "d": 4, "e": 5, "f": 6, "g": 7,"h": 8, "i": 9, "j": 10, "k": 11, "l":12, "m": 13, "n": 14, "o": 15, "p": 16, "q": 17, "r": 18, "s": 19, "t": 20,"u": 21, "v": 22, "w": 23, "x": 24, "y": 25, "z": 26}let arr = [];let str = '';text = text.replace(/[^a-zA-Z]+/g, '');for (let key in obj) {for (let i = 0; i < text.length; i++) {if(text[i].toLowerCase() == key.toLowerCase() && text[i] !== '') {arr[i] = obj[key];}}}str = arr.join(' ');return str;- return text.toLowerCase().match(/[a-z]/g) != null ? text.toLowerCase().match(/[a-z]/g).map((l) => l.charCodeAt(0)-96).join(' ') : '';
- }
def estranged_row(m: list) -> int: lens = list(map(len, m)) return next(filter(lambda l: lens.count(l[1]) == 1, enumerate(lens)))[0]
from collections import Counterdef estranged_row(m:list) -> int:estr= Counter([len(a) for a in m]).most_common(1)[0][0]for index,items in enumerate(m):if len(items) != estr:return index- def estranged_row(m: list) -> int:
- lens = list(map(len, m))
- return next(filter(lambda l: lens.count(l[1]) == 1, enumerate(lens)))[0]
memo = {} def fib(x): memKey = "%d"%x if hasattr(memo, memKey): return memo[memKey] if x >= 2: memo[memKey] = fib(x-1) + fib(x-2) return memo[memKey] return max(x, 0)
- memo = {}
- def fib(x):
- memKey = "%d"%x
- if hasattr(memo, memKey):
- return memo[memKey]
- if x >= 2:
return fib(x-1) + fib(x-2)return max(x, 0)- memo[memKey] = fib(x-1) + fib(x-2)
- return memo[memKey]
- return max(x, 0)
public class Algorithms { public static int reverseInt(int n) { return Integer.parseInt(new StringBuilder().append(n).reverse().toString()); } }
- public class Algorithms {
- public static int reverseInt(int n) {
return Integer.parseInt(new StringBuffer(String.valueOf(n)).reverse().toString());}- return Integer.parseInt(new StringBuilder().append(n).reverse().toString());
- }
- }
Avoid casting to double.
#include <algorithm> static bool willTheyMeet( int startHour1, int endHour1, int startHour2, int endHour2 ){ return !( std::max(startHour1, endHour1) < std::min(startHour2, endHour2) || std::min(startHour1, endHour1) > std::max(startHour2, endHour2) ); };
#include <cmath>- #include <algorithm>
- static bool willTheyMeet(
int startHour1,int endHour1,int startHour2,int endHour2){return !(fmax(startHour1, endHour1) < fmin(startHour2, endHour2) ||fmin(startHour1, endHour1) > fmax(startHour2, endHour2));- int startHour1, int endHour1,
- int startHour2, int endHour2
- ){
- return !(
- std::max(startHour1, endHour1) < std::min(startHour2, endHour2) ||
- std::min(startHour1, endHour1) > std::max(startHour2, endHour2)
- );
- };
def average(grades) grades.sum.to_f / grades.size unless grades.empty? end
- def average(grades)
grades.sum.fdiv(grades.length)- grades.sum.to_f / grades.size unless grades.empty?
- end
Test.assert_equals(average([1, 2, 3]), 2) Test.assert_equals(average([2, 3]), 2.5) Test.assert_not_equals(average([2, 3]), 2) Test.assert_equals(average([0,0,0]), 0) Test.assert_equals(average([0]), 0) Test.assert_equals(average([]), nil)
# 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)- Test.assert_equals(average([1, 2, 3]), 2)
- Test.assert_equals(average([2, 3]), 2.5)
- Test.assert_not_equals(average([2, 3]), 2)
- Test.assert_equals(average([0,0,0]), 0)
- Test.assert_equals(average([0]), 0)
- Test.assert_equals(average([]), nil)