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
Algorithms

More efficient implementation for large arrays.

Basic check = n(n+1)/2
vs Sorting + Linear check = O(n log n) + O(n)
vs Hash = O(n)

Code
Diff
  • class Kumite
    {
      public static function findduplicatenumber(nums: Array<Int>): Null<Int> {
        var testArray: Array<Int> = nums.copy();
        if (testArray.length < 12) {
          while (testArray.length > 0) {
            var testNum: Int = testArray.pop();
            if (testArray.indexOf(testNum) != -1) return testNum;
          }
        } else if (testArray.length < 100) {
          testArray.sort((a, b) -> a - b);
          for(i in 0...(testArray.length - 1)) {
            if(testArray[i] == testArray[i + 1]) return testArray[i];
          }
        } else {
          var myMap: Map<Int, Bool> = [];
          for(i in testArray){
            if (myMap.exists(i)) return i;
            myMap.set(i, true);
          }
        }
        return null;
      }
    }
    • class Kumite
    • {
    • public static function findduplicatenumber(nums:Array<Int>):Null<Int> {
    • var testArray:Array<Int> = nums.copy();
    • while(testArray.length > 0){
    • var testNum:Int = testArray.shift();
    • if(testArray.indexOf(testNum) != -1){
    • return testNum;
    • }
    • public static function findduplicatenumber(nums: Array<Int>): Null<Int> {
    • var testArray: Array<Int> = nums.copy();
    • if (testArray.length < 12) {
    • while (testArray.length > 0) {
    • var testNum: Int = testArray.pop();
    • if (testArray.indexOf(testNum) != -1) return testNum;
    • }
    • } else if (testArray.length < 100) {
    • testArray.sort((a, b) -> a - b);
    • for(i in 0...(testArray.length - 1)) {
    • if(testArray[i] == testArray[i + 1]) return testArray[i];
    • }
    • } else {
    • var myMap: Map<Int, Bool> = [];
    • for(i in testArray){
    • if (myMap.exists(i)) return i;
    • myMap.set(i, true);
    • }
    • }
    • return null;
    • }
    • }

Changed

    if(olives <= 0){
      return 0;
    }
    
    return (oil/olives) * 100;

To:

    return olives <= 0 ? 0 : (oil/olives) * 100;

For:
A) better readability and cleaner look(opinion)
B) Lesser lines used

Code
Diff
  • double oilRate(double olives, double oil)
    {
        return olives <= 0 ? 0 : (oil/olives) * 100;
    }
    • double oilRate(double olives, double oil)
    • {
    • if (olives <= 0)
    • return 0;
    • return (oil / olives) * 100;
    • return olives <= 0 ? 0 : (oil/olives) * 100;
    • }
Code
Diff
  • cube=x=>x**3
    • const cube = x => x ** 3;
    • cube=x=>x**3
Restricted
Code
Diff
  • converter='zero one two three four five six seven eight nine'.split().__getitem__
    • converter=lambda n:"zottffssenenwhoiieiireoruvxvgno ere ehe e nt "[n::10].strip()
    • converter='zero one two three four five six seven eight nine'.split().__getitem__

me Valentino Manuel are in a poop contest

Code
Diff
  • 9876543210
    • 0987654321
    • 9876543210
Arrays
Lists
Algorithms
Code
Diff
  • from itertools import zip_longest
    
    def mirror_fold(arr):
        """Fold a list by summing mirrored pairs from the outside in.
    
        Examples:
            [1, 2, 3, 4]    -> [5, 5]
            [1, 2, 3, 4, 5] -> [6, 6, 3]
        """
        mid = (len(arr)+1)//2
        return [a+b for a,b in zip_longest(arr[:mid], reversed(arr[mid:]), fillvalue=0)]
    • from itertools import zip_longest
    • def mirror_fold(arr):
    • """Fold a list by summing mirrored pairs from the outside in.
    • Examples:
    • [1, 2, 3, 4] -> [5, 5]
    • [1, 2, 3, 4, 5] -> [6, 6, 3]
    • """
    • left = 0
    • right = len(arr) - 1
    • folded = []
    • while left < right:
    • folded.append(arr[left] + arr[right])
    • left += 1
    • right -= 1
    • if left == right:
    • folded.append(arr[left])
    • return folded
    • mid = (len(arr)+1)//2
    • return [a+b for a,b in zip_longest(arr[:mid], reversed(arr[mid:]), fillvalue=0)]