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.

Performance

Got rid of the sort.
Don't think you can get much better using trial division.

Code
Diff
  • function getDiv(n){
        let factor0 = [];
        let factor1 = [];
        let end0 = Math.sqrt(n);
        let end1 = Math.ceil(end0);
        for (let i = 1; i !== end1; ++i) {
            if (n % i === 0) {
                factor0.push(i);
                factor1.unshift(n / i);
            }
        }
        if (end0 === end1) {
            factor0.push(end0);
        }
        factor0.push(...factor1);
        return factor0;
    }
  • 1
    var sortNumber = function(a, b){return a - b;};
    
    2
    33
    function getDiv(n){
    
    4
        var factL= [], i;
    
    5
        for (i = 1; i <= Math.floor(Math.sqrt(n)); i += 1) {
    
    2+
        let factor0 = [];
    
    3+
        let factor1 = [];
    
    4+
        let end0 = Math.sqrt(n);
    
    5+
        let end1 = Math.ceil(end0);
    
    6+
        for (let i = 1; i !== end1; ++i) {
    
    66
            if (n % i === 0) {
    
    7
                factL.push(i);
    
    8
                if (n / i !== i) factL.push(n / i);
    
    8+
                factor0.push(i);
    
    9+
                factor1.unshift(n / i);
    
    99
            }
    
    1010
        }
    
    11
        factL.sort(sortNumber);
    
    12
        return factL;
    
    12+
        if (end0 === end1) {
    
    13+
            factor0.push(end0);
    
    14+
        }
    
    15+
        factor0.push(...factor1);
    
    16+
        return factor0;
    
    1313
    }
    
Code
Diff
  • !n=n>1 ? n*!~-n : 1;factorial=!
  • 1
    def factorial(n):
    
    2
        # your code goes here
    
    3
        return
    
    1+
    !n=n>1 ? n*!~-n : 1;factorial=!
    
Recursion
Algorithms
Computability Theory
Theoretical Computer Science
Arrays
Methods
Functions
Object-oriented Programming
Control Flow
Basic Language Features
Fundamentals
Classes
Code
Diff
  • (ns flip.core)
    
    (defn flip [xs]
      (if (reversible? xs) 
        (map flip (reverse xs))
        xs))
    
  • 1
    class Array # Opens up the Array class for method creation
    
    2
      def flip
    
    3
        result = []
    
    4
        me = self.reverse # Don't fret, I'll sort the Arrays out!
    
    5
        
    
    6
        me.each do |x|
    
    7
          
    
    8
          if x.class == Array then result << x.flip # Here's the recursion.
    
    9
          else result << x
    
    10
          end
    
    11
          
    
    12
        end
    
    13
        
    
    14
        return result
    
    15
      end
    
    16
    end
    
    1+
    (ns flip.core)
    
    2+
    3+
    (defn flip [xs]
    
    4+
      (if (reversible? xs) 
    
    5+
        (map flip (reverse xs))
    
    6+
        xs))
    

Recent Moves:

Strings

Changed to what I feel is a more direct approach.

Code
Diff
  • import java.util.HashMap;
    import java.util.Map;
    import java.util.stream.Collector;
    
    class Dislexifier
    {
      public static final Map<Integer, Character> replaceMap;
    
        static {
            replaceMap = new HashMap<>();
            replaceMap.put((int) 'a', '4');
            replaceMap.put((int) 'o', '0');
            replaceMap.put((int) 'e', '3');
            replaceMap.put((int) 'i', '1');
        }
    
        public static String theDislexifier(String str) {
            return str.chars()
                    .mapToObj(c -> replaceMap.getOrDefault(c | 0x20, (char) c))
                    .collect(Collector.of(
                        () -> new StringBuilder(str.length()),
                        StringBuilder::append,
                        StringBuilder::append,
                        StringBuilder::toString
                    ));
        }
    }
    
  • 11
    import java.util.HashMap;
    
    22
    import java.util.Map;
    
    3
    import java.util.stream.Collectors;
    
    3+
    import java.util.stream.Collector;
    
    44
    55
    class Dislexifier
    
    66
    {
    
    7
      public static final Map<String, String> replaceMap;
    
    7+
      public static final Map<Integer, Character> replaceMap;
    
    88
    99
        static {
    
    1010
            replaceMap = new HashMap<>();
    
    11
            replaceMap.put("a","4");
    
    12
            replaceMap.put("o", "0");
    
    13
            replaceMap.put("e","3");
    
    14
            replaceMap.put("i","1");
    
    11+
            replaceMap.put((int) 'a', '4');
    
    12+
            replaceMap.put((int) 'o', '0');
    
    13+
            replaceMap.put((int) 'e', '3');
    
    14+
            replaceMap.put((int) 'i', '1');
    
    1515
        }
    
    1616
    1717
        public static String theDislexifier(String str) {
    
    18
            return str.chars().mapToObj(cp -> String.valueOf((char)cp))
    
    19
                    .map(c -> replaceMap.getOrDefault(c.toLowerCase(),c))
    
    20
                    .collect(Collectors.joining());
    
    18+
            return str.chars()
    
    19+
                    .mapToObj(c -> replaceMap.getOrDefault(c | 0x20, (char) c))
    
    20+
                    .collect(Collector.of(
    
    21+
                        () -> new StringBuilder(str.length()),
    
    22+
                        StringBuilder::append,
    
    23+
                        StringBuilder::append,
    
    24+
                        StringBuilder::toString
    
    25+
                    ));
    
    2121
        }
    
    2222
    }
    

Recent Moves:

Ruby golf.

Code
Diff
  • def verify_sum(a,b)a.sum==b.sum rescue !1end
    def verify_sum(a,b)a&&b&&a.sum==b.sum||!1end
  • 1
    def verify_sum(a,b)f=->x{x.chars.sum &:ord};!!(a&&b&&f.(a)==f.(b))end
    
    1+
    def verify_sum(a,b)a.sum==b.sum rescue !1end
    
    2+
    def verify_sum(a,b)a&&b&&a.sum==b.sum||!1end
    
Fundamentals
Code
Diff
  • row=lambda x,y:[*range(x,y+1)]
  • 1
    row=lambda x,y:list(range(x,y+1))
    
    1+
    row=lambda x,y:[*range(x,y+1)]
    

假裝世界沒有中文這個語文。

Code
Diff
  • remove=lambda s:"".join(filter("a".__le__,s))
  • 1
    remove=lambda s:''.join(filter(str.islower,s))
    
    1+
    remove=lambda s:"".join(filter("a".__le__,s))