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
  • function removeEveryThird(str) 
    {
     var string str = "hello world";
      var int index = 3;
     var System.out.println("Original String = " + str);
     var StringBuffer string = new StringBuffer(str);
      System.out.println("Modified String = " + string);
      return 'heloword';
    }
    • function removeEveryThird(str) {
    • // Remove the third character from every work in the string
    • // using a zero based index
    • function removeEveryThird(str)
    • {
    • var string str = "hello world";
    • var int index = 3;
    • var System.out.println("Original String = " + str);
    • var StringBuffer string = new StringBuffer(str);
    • System.out.println("Modified String = " + string);
    • return 'heloword';
    • }
Basic Language Features
Fundamentals
Control Flow
Code
Diff
  • def convert_decimal_roman(number):
        number = int(number)
        str = ""
        numDct = {1000: "M",
                  900: "CM",
                  500: "D",
                  400: "CD",
                  100: "C",
                  90: "XC",
                  50: "L",
                  40: "XL",
                  10: "X",
                  9: "IX",
                  5: "V",
                  4: "IV",
                  1: "I"}
    
        for key in numDct:
            while number >= key:
                str += numDct[key]
                number -= key
        return str
    • def convert_decimal_roman(numero):
    • num_romanos_dic = {
    • 1: 'I',
    • 5: 'V',
    • 10: 'X',
    • 50: 'L',
    • 100: 'C',
    • 500: 'D',
    • 1000: 'M'
    • }
    • list_num_rom = [{'key': x, 'value': y} for x, y in num_romanos_dic.items()]
    • size_num = len(numero)
    • output = []
    • for i in range(size_num):
    • num = numero[i:]
    • num_unit = int(num)
    • numextre_izq = int(num[0])
    • pref = []
    • for i in range(1, len(list_num_rom), 2):
    • if num_unit >= list_num_rom[i-1]['key'] and num_unit < list_num_rom[i+1]['key']:
    • pref.append(list_num_rom[i-1]['value'])
    • pref.append(list_num_rom[i]['value'])
    • pref.append(list_num_rom[i+1]['value'])
    • def convert_decimal_roman(number):
    • number = int(number)
    • str = ""
    • numDct = {1000: "M",
    • 900: "CM",
    • 500: "D",
    • 400: "CD",
    • 100: "C",
    • 90: "XC",
    • 50: "L",
    • 40: "XL",
    • 10: "X",
    • 9: "IX",
    • 5: "V",
    • 4: "IV",
    • 1: "I"}
    • if numextre_izq < 4 and numextre_izq > 0:
    • output.append(pref[0]*numextre_izq)
    • if numextre_izq == 4:
    • output.extend(pref[0:2])
    • if numextre_izq == 5:
    • output.append(pref[1])
    • if numextre_izq > 5 and numextre_izq < 9:
    • output.append(pref[1] + pref[0]*(numextre_izq-5))
    • if numextre_izq == 9:
    • output.extend(pref[::2])
    • output = ''.join(output)
    • return output
    • for key in numDct:
    • while number >= key:
    • str += numDct[key]
    • number -= key
    • return str
Code
Diff
  • #!/usr/bin/lua
    
    local solution = {}
    
    function solution.sort_values(arr)
      table.sort(arr, function(a, b) return a < b end)  
      return arr
    end
    
    return solution
    • from __future__ import annotations
    • from collections import Counter
    • #!/usr/bin/lua
    • def sort_values(vals:list[int]) -> list[int]:
    • #Given an array of size N containing only 0s, 1s, and 2s;
    • #sort the array in ascending order.
    • assert set(vals) <= {0,1,2}
    • return counting_sort(vals)
    • # O(n+k) instead of n log(n)
    • local solution = {}
    • def counting_sort(vals:list[T]) -> list[T]:
    • res = []
    • c = Counter(vals)
    • for k,amt in sorted(c.items()):
    • res += [k]*amt
    • return res
    • function solution.sort_values(arr)
    • table.sort(arr, function(a, b) return a < b end)
    • return arr
    • end
    • return solution
Objects
Data Types
Strings
Code
Diff
  • export const transform = (source: Record<string, any>): Record<string, any> => {
      
      // Array of keys
      const keys = Object.keys(source);
      
      // Array of splitted keys
      const splitted_keys: string[][] = [];
      
      // Splitting keys
      keys.forEach((item, i) => {
        
        // If name isn't underscore only
        if (item !== '_') {
          splitted_keys.push(item.split('_'));
          
        // If name is underscore only
        } else {
          splitted_keys.push(['_']);
        }
      });
      
      // Resulting object
      const result = Object.create(null);
      
      // Creating objects
      splitted_keys.forEach((item, index) => {
        
        // Merging objects
        Object.assign(result,
          recursiveCreateObject(
          
            // New object
            Object.create(null),
          
            // Array of keys
            item,
          
            // Final value
            source[keys[index]]
          )
        );
      });
      
      return result;
    }
    
    /**
     * @describe Function, that recursively creates objects
     * @param obj Object, that will be nested
     * @param keys Keys that will be used in nesting
     * @param final_value Final value, that will be used, when keys array will be empty
     * @returns Nested object
     */
    const recursiveCreateObject = (obj: any, keys: string[], final_value: any): any => {
      
      // If no keys in array
      if (keys.length === 0) {
        return obj[keys[0]] = final_value;
      }
      
      // Shift first value in array
      const shifted_symbol: string = keys.shift() as string;
      
      // Creating new nested object
      obj = {[shifted_symbol]: recursiveCreateObject(Object.create(null), keys, final_value)};
      
      // Returning nested object
      return obj;
    }
    • export const transform = (source: Record<string, any>): Record<string, any> => {
    • const target = Object.create(null);
    • // TODO: handle invalid property
    • Object.entries(source).forEach(([key, value]) => {
    • key.split("_").slice(0, -1).reduce((node: Record<string, any>, element: string) => {
    • return node[element] ??= {};
    • }, target)[key.slice(key.lastIndexOf("_") + 1)] = value;
    • });
    • return target;
    • // Array of keys
    • const keys = Object.keys(source);
    • // Array of splitted keys
    • const splitted_keys: string[][] = [];
    • // Splitting keys
    • keys.forEach((item, i) => {
    • // If name isn't underscore only
    • if (item !== '_') {
    • splitted_keys.push(item.split('_'));
    • // If name is underscore only
    • } else {
    • splitted_keys.push(['_']);
    • }
    • });
    • // Resulting object
    • const result = Object.create(null);
    • // Creating objects
    • splitted_keys.forEach((item, index) => {
    • // Merging objects
    • Object.assign(result,
    • recursiveCreateObject(
    • // New object
    • Object.create(null),
    • // Array of keys
    • item,
    • // Final value
    • source[keys[index]]
    • )
    • );
    • });
    • return result;
    • }
    • /**
    • * @describe Function, that recursively creates objects
    • * @param obj Object, that will be nested
    • * @param keys Keys that will be used in nesting
    • * @param final_value Final value, that will be used, when keys array will be empty
    • * @returns Nested object
    • */
    • const recursiveCreateObject = (obj: any, keys: string[], final_value: any): any => {
    • // If no keys in array
    • if (keys.length === 0) {
    • return obj[keys[0]] = final_value;
    • }
    • // Shift first value in array
    • const shifted_symbol: string = keys.shift() as string;
    • // Creating new nested object
    • obj = {[shifted_symbol]: recursiveCreateObject(Object.create(null), keys, final_value)};
    • // Returning nested object
    • return obj;
    • }
Code
Diff
  • const revstr = str => [...str].reduceRight((a, c) => a + c, '')
    • const revstr = str => [...str].reverse().join``
    • const revstr = str => [...str].reduceRight((a, c) => a + c, '')
Code
Diff
  • const parse = (value = '') => {
      // if valid email, return true, else return false
      return true;
    }
    const email = "Yjimenezar001@gmail.com";
    Test.assertEquals(true, parse(email1));
    • const parse = (value = '') => {
    • // if valid email, return true, else return false
    • return true;
    • }
    • }
    • const email = "Yjimenezar001@gmail.com";
    • Test.assertEquals(true, parse(email1));
Code
Diff
  • public class Kata {
      public static boolean detectPalindrome(String userWord) {
        // Detect whether this string is a palindrome
        String backwardsWord = new StringBuilder(userWord).reverse().toString();
        if (!userWord.equals(backwardsWord)) {
          return false;
        }
        return true;
      }
    }
    • public class Kata {
    • public static boolean detectPalindrome(String userWord) {
    • // Detect whether this string is a palindrome
    • String backwardsWord = new StringBuilder(userWord).reverse().toString();
    • if (!userWord.equals(backwardsWord)) {
    • return false;
    • }
    • return true;
    • }
    • }

dk m

Code
Diff
  • interface HighLow {
        static int[] findLargestAndSmallest(int[] nums) {
            // Change min and max below to be the highest and lowest values
            // in the nums array provided to the function
            int min = 0;  
            int max = 100;
          
          for(int i; i< findLargestAndSmallest; i++)
              {
              min = nums[0];
              if(nums[i] < min)
                min = nums[i];
              }
          
          for(int i; i< findLargestAndSmallest; i++)
              {
              max = nums[0];
              if(nums[i] > max)
                max = nums[i];
              }
    
    
            return new int[]{min, max};
        }
    }
    
    • interface HighLow {
    • static int[] findLargestAndSmallest(int[] nums) {
    • // Change min and max below to be the highest and lowest values
    • // in the nums array provided to the function
    • int min = 0;
    • int max = 100;
    • for(int i; i< findLargestAndSmallest; i++)
    • {
    • min = nums[0];
    • if(nums[i] < min)
    • min = nums[i];
    • }
    • for(int i; i< findLargestAndSmallest; i++)
    • {
    • max = nums[0];
    • if(nums[i] > max)
    • max = nums[i];
    • }
    • return new int[]{min, max};
    • }
    • }
Code
Diff
  •     import static java.util.stream.DoubleStream.of;
    import static org.apache.commons.lang3.ArrayUtils.reverse;
    
    import java.util.*;
    
    interface DeleteDuplicates {
      static double[] deleteDups(double[] nums) {
         return Arrays.stream(nums).distinct().toArray();
        }
    }
    • import static java.util.stream.DoubleStream.of;
    • import static java.util.stream.DoubleStream.of;
    • import static org.apache.commons.lang3.ArrayUtils.reverse;
    • import java.util.*;
    • interface DeleteDuplicates {
    • static double[] deleteDups(double[] a) {
    • // Given an array, eliminate duplicate values and return the array
    • return a;
    • }
    • static double[] deleteDups(double[] nums) {
    • return Arrays.stream(nums).distinct().toArray();
    • }
    • }

factorial with stack, for big int

Code
Diff
  • function factorial (n) {
      const stack = [[n, 1]];
    
      while (stack.length > 0) {
        const [curr, result] = stack.pop();
    
        if(curr === 0 || curr === 1) {
          return result;
        }
        stack.push([curr - 1, result * curr]);
      }
    }
    • function factorial (n) {
    • if (n === 0 || n === 1) {
    • return 1;
    • } else {
    • return n * factorial(n - 1);
    • const stack = [[n, 1]];
    • while (stack.length > 0) {
    • const [curr, result] = stack.pop();
    • if(curr === 0 || curr === 1) {
    • return result;
    • }
    • stack.push([curr - 1, result * curr]);
    • }
    • }