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
Code
Diff
  • import java.util.*;
    interface HighLow {
      static int[] printLargestAndSmallest(int[] nums) {
        Arrays.sort(nums);
        return new int[] {nums[0], nums[nums.length-1]};
      }
    }
    • import java.util.*;
    • interface HighLow {
    • static int[] printLargestAndSmallest(int[] nums) {
    • int min = nums[0], max = nums[0];
    • for (int n : nums) {
    • if (n < min) min = n;
    • if (n > max) max = n;
    • }
    • return new int[] {min, max};
    • Arrays.sort(nums);
    • return new int[] {nums[0], nums[nums.length-1]};
    • }
    • }

As far as I can tell, you don't want a simple number but a prime number.
I added 5075 as it's also not a prime number.

https://en.wikipedia.org/wiki/List_of_prime_numbers

Code
Diff
  • export const checkIsPrimeNumber = (n: number) => 
    {
      if (!Number.isInteger(n)) return false;
      for (var i = 2; i < n; i++) {
        if (n % i === 0) return false;
      }
      return n > 1;
    };
    • export const checkIsNumberSimple = (number: number) => {
    • // Check if the number is integer
    • if (number % 1 != 0) return false;
    • if (number < 2) return false;
    • if (number != 2 && number % 2 == 0) return false;
    • if (number != 3 && number % 3 == 0) return false;
    • return true;
    • export const checkIsPrimeNumber = (n: number) =>
    • {
    • if (!Number.isInteger(n)) return false;
    • for (var i = 2; i < n; i++) {
    • if (n % i === 0) return false;
    • }
    • return n > 1;
    • };

Only generate the values with fast-check.

Fundamentals
Numbers
Data Types
Integers
Code
Diff
  • public static class Kata
    {
        public static bool IsOdd(int input, int div)
        {
            if (input % div == 0)
              return true;
            return false;
        }
    }
    • public static class Kata
    • {
    • public static bool IsOdd(int input)
    • public static bool IsOdd(int input, int div)
    • {
    • if (input % 2 == 0)
    • {
    • return false;
    • }
    • else
    • {
    • return true;
    • }
    • if (input % div == 0)
    • return true;
    • return false;
    • }
    • }

The original author did not specify what to do in edgecases, so I added what I think is most sensible.

Code
Diff
  • def abbrev(s):
        length = len(s)
        if length < 4:
            return s
        return s[0] + str(length - 2) + s[-1]
    • def abbrev(s):
    • return s[0] + str(len(s[1:-1])) + s[-1]
    • length = len(s)
    • if length < 4:
    • return s
    • return s[0] + str(length - 2) + s[-1]
Code
Diff
  • prod = lambda numbers: numbers[0] * (prod(numbers[1:]) or 1) if numbers else 0
    • def prod(numbers):
    • return numbers[0] * (prod(numbers[1:]) or 1) if len(numbers) else 0
    • prod = lambda numbers: numbers[0] * (prod(numbers[1:]) or 1) if numbers else 0
Code
Diff
  • def digital_root(n):
        while n > 9:
            sum = 0
            while n != 0:
                sum += n % 10
                n //= 10
            n = sum
        return n
    • def digital_root(n):
    • "NOPE"
    • while n > 9:
    • sum = 0
    • while n != 0:
    • sum += n % 10
    • n //= 10
    • n = sum
    • return n

You have to create an abbreviation function. It will take string and return a string while taking the first and last char of word and replace the remaining with the number of chars in it.

For example:
internationalization => i18n
Localization => L10n
Deepak-Vishwa => D4k-V4a
I Love India => I L2e I3a

Code
Diff
  • const abbrev = (text = "") => {
      return text.replace(/\w{4,}/g, s => {
        l = s.length;
        return `${s[0]}${l - 2}${s[l - 1]}`;
      });
    };
    
    • const abbrevWord = (text = "") => {
    • if (text.length < 3) return text;
    • const first = text.charAt(0);
    • const last = text.slice(-1);
    • const remLen = text.length - 2;
    • return `${first}${remLen}${last}`;
    • };
    • const simpleChars = /\w+/g;
    • const abbrev = (text = "") => {
    • return text.replace(simpleChars, (matched) => abbrevWord(matched));
    • return text.replace(/\w{4,}/g, s => {
    • l = s.length;
    • return `${s[0]}${l - 2}${s[l - 1]}`;
    • });
    • };
Fundamentals
Code
Diff
  • e=lambda n:n-n%2
    • e=lambda n:n-(n&1)
    • e=lambda n:n-n%2