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
  • class Sort:
    
        def merge_sort(self, nums):
            if nums == None: return None
            elif len(nums) <= 1: return nums
          
            vLeft = self.merge_sort(nums[:len(nums) // 2])
            vRight= self.merge_sort(nums[len(nums) // 2:])                 
            lLeft,lRight = len(vLeft),len(vRight)
            i,j,k = 0,0,0
            
            while i < lLeft and j < lRight:
                if vLeft[i] < vRight[j]:
                    nums[k] = vLeft[i]
                    i += 1
                else:
                    nums[k] = vRight[j]
                    j += 1
                k += 1
    
            while i < lLeft:
                nums[k] = vLeft[i]
                i += 1
                k += 1
    
            while j < lRight:
                nums[k] = vRight[j]
                j += 1
                k += 1
    
            return nums
    
    • class Sort:
    • def merge_sort(self, nums):
    • if nums == None: return None
    • if len(nums) > 1:
    • mid = len(nums) // 2
    • lefthalf = nums[:mid]
    • righthalf = nums[mid:]
    • self.merge_sort(lefthalf)
    • self.merge_sort(righthalf)
    • i = 0
    • j = 0
    • k = 0
    • while i < len(lefthalf) and j < len(righthalf):
    • if lefthalf[i] < righthalf[j]:
    • nums[k] = lefthalf[i]
    • i += 1
    • else:
    • nums[k] = righthalf[j]
    • j += 1
    • k += 1
    • while i < len(lefthalf):
    • nums[k] = lefthalf[i]
    • elif len(nums) <= 1: return nums
    • vLeft = self.merge_sort(nums[:len(nums) // 2])
    • vRight= self.merge_sort(nums[len(nums) // 2:])
    • lLeft,lRight = len(vLeft),len(vRight)
    • i,j,k = 0,0,0
    • while i < lLeft and j < lRight:
    • if vLeft[i] < vRight[j]:
    • nums[k] = vLeft[i]
    • i += 1
    • k += 1
    • while j < len(righthalf):
    • nums[k] = righthalf[j]
    • else:
    • nums[k] = vRight[j]
    • j += 1
    • k += 1
    • k += 1
    • while i < lLeft:
    • nums[k] = vLeft[i]
    • i += 1
    • k += 1
    • while j < lRight:
    • nums[k] = vRight[j]
    • j += 1
    • k += 1
    • return nums

Changed from a static variable to a dynamic function.

Code
Diff
  • module Solution
      export greet
    
      function greet( whom::String )
        "Hello " * whom * "!"  
      end
      
    end
    
    • println("Hello Julia!")
    • const hello = "world"
    • module Solution
    • export greet
    • function greet( whom::String )
    • "Hello " * whom * "!"
    • end
    • end
Code
Diff
  • def add(string, option):
        odd,even = 0,0
        for x in string:
            x = int(x)
            if x%2 ==0:even+=x
            if x%2 ==1:odd+=x
        if option ==0:
            return odd+even
        return even if option == 2 else odd
    • def add(string, option):
    • even_list = []
    • odd_list = []
    • all_sum = 0
    • for num in string:
    • num = int(num)
    • all_sum += num
    • if num % 2 == 0:
    • even_list.append(num)
    • if num % 2 != 0:
    • odd_list.append(num)
    • if option == 0:
    • return all_sum
    • if option == 1:
    • return sum(odd_list)
    • if option == 2:
    • return sum(even_list)
    • odd,even = 0,0
    • for x in string:
    • x = int(x)
    • if x%2 ==0:even+=x
    • if x%2 ==1:odd+=x
    • if option ==0:
    • return odd+even
    • return even if option == 2 else odd
Code
Diff
  • def distance(a):
        y,y1 = 0,0
        for i in range(len(a)):
            if "y" in a[i]: y = i
            if "x" in a[i]: y1 = i
            
        x ,x1 = a[y].index("y"), a[y1].index("x")
        return abs(x -x1) + abs(y-y1)
    • def distance(array):
    • for i in range(len(array)):
    • if "y" in array[i] : y = abs(array[i].index("y") - i)
    • if "x" in array[i] : x = abs(array[i].index("x") - i)
    • return (x+y)
    • def distance(a):
    • y,y1 = 0,0
    • for i in range(len(a)):
    • if "y" in a[i]: y = i
    • if "x" in a[i]: y1 = i
    • x ,x1 = a[y].index("y"), a[y1].index("x")
    • return abs(x -x1) + abs(y-y1)
Code
Diff
  • def fizz_buzz(n):
        return ['FizzBuzz' if (i % 15 == 0) else 'Fizz' if(i % 3 == 0) else 'Buzz' if(i % 5 == 0) else i for i in range(1,n)]
        
    • def fizz_buzz(n):
    • for i in range(1, n):
    • yield "Fizz" * (i % 3 == 0) + "Buzz" * (i % 5 == 0) or i
    • return ['FizzBuzz' if (i % 15 == 0) else 'Fizz' if(i % 3 == 0) else 'Buzz' if(i % 5 == 0) else i for i in range(1,n)]
Fundamentals
Strings
Data Types

A different approach from the one above, done in one line.

Code
Diff
  • const minutes = i => `${Math.trunc(i / 60)}:${i % 60 < 10 ? "0" : ""}${i % 60}`;
    • const toHours = i => Math.floor(i / 60);
    • const setDigits = i => `0${i}`.slice(-2);
    • const getTime = i => [toHours(i), i % 60];
    • const toTime = arr => `${arr[0]}:${setDigits(arr[1])}`;
    • const minutes = i => toTime(getTime(i));
    • const minutes = i => `${Math.trunc(i / 60)}:${i % 60 < 10 ? "0" : ""}${i % 60}`;

Using Math.max

Code
Diff
  • public class BiggerNum{
    
      /**
       * @param a integer of param1
       * @param b integer of param2
       * @return the bigger integer of a and b
       * If a equals b, return either one
       */
      public static int compare(int a, int b) {
        return Math.max(a,b);
      }
    }
    • public class BiggerNum{
    • /**
    • * @param a integer of param1
    • * @param b integer of param2
    • * @return the bigger integer of a and b
    • * If a equals b, eiter one is acceptance
    • * If a equals b, return either one
    • */
    • public static int compare(int a, int b) {
    • return a >= b ? a : b;
    • return Math.max(a,b);
    • }
    • }

Using OP's description:

  • Premium: UltraHD and 4 devices
  • Standard: HD and 2 devices
  • Essential: 1 device

Fixed checks and added invalid case for a list of parameters that does not work. Changed the two bool parameters to an enum, since you probably won't be purchasing both HD and UHD simultaneously.

Code
Diff
  • using System;
    
    public enum Quality { SD, HD, UHD }
    
    public class TV
    {
      public static string GetContract( int numDevices, Quality quality)
      {
        string result = "INVALID";
        
        if (numDevices == 4 && quality == Quality.UHD)
          result = "PREMIUM";
        else if (numDevices == 2 && quality == Quality.HD)
          result = "STANDARD";
        else if (numDevices == 1 && quality == Quality.SD)
          result = "ESSENTIAL";
        
        return result;
      }
    }
            
    • using System;
    • public class Kata
    • {
    • public static string GetContract( int numberOfDevices, bool ultraHd, bool hd)
    • {
    • string result = "ESSENTIEL";
    • if (numberOfDevices>2 || ultraHd)
    • {
    • result = "PREMIUM";
    • }
    • else
    • {
    • if (numberOfDevices == 2 || hd)
    • {
    • result = "STANDARD";
    • }
    • }
    • return result;
    • public enum Quality { SD, HD, UHD }
    • }
    • public class TV
    • {
    • public static string GetContract( int numDevices, Quality quality)
    • {
    • string result = "INVALID";
    • if (numDevices == 4 && quality == Quality.UHD)
    • result = "PREMIUM";
    • else if (numDevices == 2 && quality == Quality.HD)
    • result = "STANDARD";
    • else if (numDevices == 1 && quality == Quality.SD)
    • result = "ESSENTIAL";
    • return result;
    • }
    • }