Begin a new Kumite
Search
About
  • Filter by Language:
  • 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.

wichuvs.wichuFailed Tests

F# Basics

Code
Diff
  • let add a b = a + b
    let square x = x * x
    let a = add 1 2 |> add 3 |> add 4 |> square
    
    printfn "%i" a
    
    
    let add1 x = x + 1
    let b = (square >> add1) 2
    
    printfn "%i" b
  • 11
    let add a b = a + b
    
    22
    let square x = x * x
    
    3
    let result = add 1 2 |> add 3 |> add 4 |> square
    
    3+
    let a = add 1 2 |> add 3 |> add 4 |> square
    
    44
    5
    printfn result
    
    5+
    printfn "%i" a
    
    6+
    7+
    8+
    let add1 x = x + 1
    
    9+
    let b = (square >> add1) 2
    
    10+
    11+
    printfn "%i" b
    
wichuFailed Tests

Hello World

printfn "%s" "Hello World"

power function

let rec power a n = match n with | 0 -> 1 | _ -> a * power a (n - 1)

printfn "%i" (power 2 4)
printfn "%i" (power 3 3)
printfn "%i" (power 4 2)

Raise 2 to the power 10 without using Math.pow or defining your own function.

Make it in one expression.

let x = let rec pow2 n = match n with | 0 -> 1 | _ -> 2 * pow2 (n - 1) in pow2 10
printfn "%i" x
Arrays
Code
Diff
  • const remove=(arr, n)=>arr.filter((_,i)=>i!=n)
  • 1
    function remove (arr, n) {
    
    2
      if (n < 0 || n >= arr.length) return arr;
    
    3
      arr.splice(n, 1);
    
    4
      return arr;
    
    5
    }
    
    1+
    const remove=(arr, n)=>arr.filter((_,i)=>i!=n)
    

Recent Moves:

Code
Diff
  • import java.util.*;;
    
    class Solution {
      public static int peakIndex(int[] nums) {
        if (nums.length == 1) return 0;
        if (nums.length == 2) return nums[0] > nums[1] ? 0 : 1;
        
        boolean ascending = false;
        
        for (int i = 0; i < nums.length - 1; ++i) {
          if (nums[i] < nums[i + 1]) {
            ascending = true;
          } else {
            if (ascending && nums[i] > nums[i + 1]) {
              return i;
            }
            ascending = false;
          }
        }
        
        if (ascending) {
          return nums.length - 1;
        } else {
          return -1;
        }
      }
    }
  • 11
    import java.util.*;;
    
    22
    33
    class Solution {
    
    44
      public static int peakIndex(int[] nums) {
    
    5
        int left = 0;
    
    6
        int right = nums.length - 1;
    
    7
        int peak = -1;
    
    5+
        if (nums.length == 1) return 0;
    
    6+
        if (nums.length == 2) return nums[0] > nums[1] ? 0 : 1;
    
    88
        
    
    9
        while(left <= right) {
    
    10
          if(left == right) {
    
    11
            peak = left;
    
    12
            break;
    
    13
          }
    
    14
          
    
    15
          int mid = (left + right) / 2;
    
    16
          
    
    17
          if(nums[mid] < nums[mid + 1]) {
    
    18
            left = mid + 1;
    
    8+
        boolean ascending = false;
    
    9+
        
    
    10+
        for (int i = 0; i < nums.length - 1; ++i) {
    
    11+
          if (nums[i] < nums[i + 1]) {
    
    12+
            ascending = true;
    
    1919
          } else {
    
    20
            right = mid;
    
    14+
            if (ascending && nums[i] > nums[i + 1]) {
    
    15+
              return i;
    
    16+
            }
    
    17+
            ascending = false;
    
    2121
          }
    
    2222
        }
    
    2323
        
    
    24
        return peak;
    
    21+
        if (ascending) {
    
    22+
          return nums.length - 1;
    
    23+
        } else {
    
    24+
          return -1;
    
    25+
        }
    
    2525
      }
    
    2626
    }
    
Code
Diff
  • import java.util.*;
    import java.util.stream.*;
    
    class Solution {
      public static String largestNumber(Integer[] nums) {
        final StringBuilder sb = new StringBuilder();
        return Arrays.stream(nums)
              .parallel()
              .map((n) -> n.toString())
              .sorted(Solution::compareNumberString)
              .collect(Collectors.joining())
              .toString();
      }
      
      private static int compareNumberString(String s1, String s2) {
        if (s2.startsWith(s1)) return compareNumberString(s2.substring(s1.length()), s1);
        if (s1.startsWith(s2)) return compareNumberString(s1.substring(s2.length()), s2);
        return s2.compareTo(s1);
      }
    }
  • 11
    import java.util.*;
    
    2+
    import java.util.stream.*;
    
    22
    33
    class Solution {
    
    44
      public static String largestNumber(Integer[] nums) {
    
    5
        Arrays.sort( nums, new Comparator<Integer>() {
    
    6
          
    
    7
          @Override
    
    8
          public int compare(Integer a, Integer b) {
    
    9
            String aStr = a.toString();
    
    10
            String bStr = b.toString();
    
    11
            
    
    12
            return (aStr + bStr).compareTo(bStr + aStr) * -1;
    
    13
          }
    
    14
          
    
    15
        } );
    
    16
        
    
    17
        String result = "";
    
    18
        for(Integer num : nums) {
    
    19
          result += num.toString();
    
    20
        }
    
    21
        
    
    22
        return result;
    
    6+
        final StringBuilder sb = new StringBuilder();
    
    7+
        return Arrays.stream(nums)
    
    8+
              .parallel()
    
    9+
              .map((n) -> n.toString())
    
    10+
              .sorted(Solution::compareNumberString)
    
    11+
              .collect(Collectors.joining())
    
    12+
              .toString();
    
    13+
      }
    
    14+
      
    
    15+
      private static int compareNumberString(String s1, String s2) {
    
    16+
        if (s2.startsWith(s1)) return compareNumberString(s2.substring(s1.length()), s1);
    
    17+
        if (s1.startsWith(s2)) return compareNumberString(s1.substring(s2.length()), s2);
    
    18+
        return s2.compareTo(s1);
    
    2323
      }
    
    2424
    }
    
public class Primes {
  public static boolean isAPrime(int number) {
    return true;
  }
}
Polymer({
    is: "pedal-assist",
    properties:{
      ppc:{
        type:Number,
        value:30,
      },
      gap:{
        type:Number,
        computed:"getGap(lPedel,rPedel)",
      },
      cycle:{
        type:Number,
        value:.5,
      },
    },
    left: function(undefined){
      this.lPedel = performance.now()

    },
    right: function(undefined){
      this.rPedel = performance.now()
    },
    getGap: function(lPedel,rPedel){
      var newGap = Math.sqrt((lPedel - rPedel) * (lPedel - rPedel))

      var r1 = this.gapOld / this.gap
      var r2 = this.gap / newGap
      console.log(r1,r2,newGap)
      if (r1 < 1.2 && r1 > .8 && r2 < 1.2 && r2 > .8) {
       this.runMotor(this.cycle,this.ppc,this.gap)
      }
      this.gapOld = this.gap
      return newGap
    },
    runMotor: function(cycle,ppc,time){
      var n= Math.floor(ppc*cycle)
      for (var i=1;i<n;i++) {
        setTimeout(function(that){
          if (that.black == 0) {
            that.set("black", 12)
            that.yellow = 0
            that.red = -12
          } else if (that.yellow == 0) {
            that.black = -12 
            that.yellow = 12
            that.red = 0
          } else if (that.red == 0) {
            that.black = 0 
            that.yellow = -12
            that.red = 12
          } 
        }, (time*cycle)*(i/n),this)

          console.log((time*cycle)*(i/n))
      }
      setTimeout(function(that){
        that.black = 0 
        that.yellow = 0
        that.red = 0
      }, (time*cycle)+10,this)
    },
  })