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.

First Kumite don't really know what I'm supposed to be doing but I refactored this code a bit.

Shouldn't use arrow functions except for delegates imo. You don't need calling context for this function so no need for it.

Just iterate backwards over the array instead of doing unecessary subtractiosn.

Code
Diff
  • function invert(str) {
      let rev_str = "";
      
      for (let i = str.length-1; i >=0 ; i--) {
        rev_str += str[i];
      }
      
      return rev_str;
    }
    
  • 1-const invert = str => {
    1+function invert(str) {
    22 let rev_str = "";
    33
    4- for (let i = 0; i < str.length; i++) {
    5- rev_str += str[str.length - 1 - i];
    4+ for (let i = str.length-1; i >=0 ; i--) {
    5+ rev_str += str[i];
    66 }
    77
    88 return rev_str;
    99 }

50,000 chokes my browser way too much showing all that output => Node 10 (also Chai then) => Not displaying much output

And, it looks like it's time to golf, so here goes (plus $ and _ for giggles)

Also, enforced more character limit

And variable name is one letter -- better for golfing

Code
Diff
  • c=($,_)=>_*($/_|0)
  • 1-closestMultiple=(N,n)=>n*(N/n+0.5>>0)
    1+c=($,_)=>_*($/_|0)
Mathematics
Algorithms
Numbers
Code
Diff
  • average=a=>a>''?require('ramda').mean(a):a.x
  • 1-average=a=>a.length?require('ramda').mean(a):a.x
    1+average=a=>a>''?require('ramda').mean(a):a.x

Ask some children - "How old are you?". They always say something strange... Lets help them.

Their age is hidden in what they say.

fn get_age(age: &str) -> u32 {
    age.split("").filter_map(|s| s.parse().ok()).fold(1, |a, b: u32| a * b)
}
Code
Diff
  • public class Sum
    {
       public int GetSum(int a, int b) => a + b;
    }
  • 1-using System;
    22 public class Sum
    33 {
    4- public int GetSum(int a, int b)
    5- {
    6- return a + b;
    7- }
    3+ public int GetSum(int a, int b) => a + b;
    88 }

I have decided to update the scope to take a list and the number of terms that you wish to find the maximum product of.

This should be a more general solution to the problem.

I have included error handling for if the number of terms exceeds the length of sequence.

Code
Diff
  • import numpy
    import itertools
    
    def maximum_product_of_three(sequence, terms):
        max = 0
        combos = itertools.combinations(sequence, terms)
        
        for set in combos:
            if numpy.prod(set) > max:
                max = numpy.prod(set)
                combo = set
    
        return combo, max
  • 1-def maximum_product_of_three(a):
    2- a.sort()
    3- return max(a[0]*a[1]*a[-1], a[-3]*a[-2]*a[-1])
    1+import numpy
    2+import itertools
    3+
    4+def maximum_product_of_three(sequence, terms):
    5+ max = 0
    6+ combos = itertools.combinations(sequence, terms)
    7+
    8+ for set in combos:
    9+ if numpy.prod(set) > max:
    10+ max = numpy.prod(set)
    11+ combo = set
    12+
    13+ return combo, max
Code
Diff
  • def sorting(list):
        return sorted(list)
  • 1-sorting = sorted # eh?
    1+def sorting(list):
    2+ return sorted(list)