Start a new Kumite
AllAgda (Beta)BF (Beta)CCFML (Beta)ClojureCOBOL (Beta)CoffeeScriptCommonLisp (Beta)CoqC++CrystalC#D (Beta)DartElixirElm (Beta)Erlang (Beta)Factor (Beta)Forth (Beta)Fortran (Beta)F#GoGroovyHaskellHaxe (Beta)Idris (Beta)JavaJavaScriptJulia (Beta)Kotlinλ Calculus (Beta)LeanLuaNASMNim (Beta)Objective-C (Beta)OCaml (Beta)Pascal (Beta)Perl (Beta)PHPPowerShell (Beta)Prolog (Beta)PureScript (Beta)PythonR (Beta)RacketRaku (Beta)Reason (Beta)RISC-V (Beta)RubyRustScalaShellSolidity (Beta)SQLSwiftTypeScriptVB (Beta)
Show only mine

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.

Ad
Ad
Code
Diff
  • 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"

Code
Diff
  • 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));
    • }
    • }
Code
Diff
  • 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(' ') : '';
    • }
Graphs
Data Structures
Algorithms
Logic
Code
Diff
  • 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 Counter
    • def 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]
Code
Diff
  • 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)
Code
Diff
  • 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.

Code
Diff
  • #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)
    • );
    • };
Mathematics
Algorithms
Logic
Numbers
Data Types
Code
Diff
  • 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