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
  • ok=$=>"ok";
    • let ok =_=> "ok";
    • ok=$=>"ok";
Code
Diff
  • getChange=(x,y)=>Math.floor(10*(y-x))/10
    
    
    
    
    
    • getChange=
    • (__,_,___=100)=>(
    • _=(_-__
    • )*(__=___)
    • )?(~~_/
    • __):_
    • getChange=(x,y)=>Math.floor(10*(y-x))/10
Code
Diff
  • import java.util.stream.Collectors;
    import java.util.stream.IntStream;
    
    class Solution {
        public static String numberOfNumbers(final int value) {
    
            return IntStream.rangeClosed(1, Math.abs(value))
                    .mapToObj(n -> new String(new char[n]).replace("\0", String.valueOf(n)))
                    .collect(Collectors.joining(value > 0 ? "-" : "+"));
        }
    }
    • import java.util.stream.Collectors;
    • import java.util.stream.IntStream;
    • import java.util.stream.Stream;
    • class Solution {
    • public static String numberOfNumbers(final int value) {
    • if (value == 0) {
    • return "";
    • }
    • final String delimiter = value > 0 ? "-" : "+";
    • return IntStream.rangeClosed(1, Math.abs(value))
    • .mapToObj(n -> new String(new char[n]).replace("\0", String.valueOf(n)))
    • .collect(Collectors.joining(delimiter));
    • .collect(Collectors.joining(value > 0 ? "-" : "+"));
    • }
    • }
Algorithms
Logic

We have n piles of apples, and we want to move the piles into a single large pile using the least possible amount of energy. Only two piles can be combined at a time and two piles with a and b apples can be combined together with the cost of (a+b) energy units.

We want to know the minimum amount of energy required to combine all piles of apples together.

Input:
apple(n, lst)
where lst contains n numbers representing the number of apples in each pile.

Code
Diff
  • #include<algorithm>
    using namespace std;
    int apple(int n, int* a)
    {
       if (n < 2) return 0;
       int* end = a+n;
       int sum = 0;
       while (end > a+1)
       {
          std::make_heap(a, end, greater<int>());
          std::pop_heap(a, end, greater<int>());
          --end;
          sum += (*a += *end);
       }
       return sum;
    }
    • #include<stdio.h>
    • #include<queue>
    • #include<algorithm>
    • using namespace std;
    • int apple(int n,int* a)
    • int apple(int n, int* a)
    • {
    • priority_queue<int,vector<int>,greater<int> >q;
    • for(int i=0; i<n; i++)
    • q.push(a[i]);
    • int ans=0,tmp;
    • while(q.size()>=2)
    • {
    • tmp=0;
    • tmp+=q.top();
    • q.pop();
    • tmp+=q.top();
    • q.pop();
    • ans+=tmp;
    • q.push(tmp);
    • }
    • return ans;
    • if (n < 2) return 0;
    • int* end = a+n;
    • int sum = 0;
    • while (end > a+1)
    • {
    • std::make_heap(a, end, greater<int>());
    • std::pop_heap(a, end, greater<int>());
    • --end;
    • sum += (*a += *end);
    • }
    • return sum;
    • }

Refactored for acepting any number basis.

Code
Diff
  • function getIDS(string $number) {
      $number = str_split($number);
      array_walk($number, function($digit) use ($number) {
        return intval($digit); 
      });
      return array_sum($number);
    }
    • function getIDS($number) {
    • return array_sum(str_split($number));
    • function getIDS(string $number) {
    • $number = str_split($number);
    • array_walk($number, function($digit) use ($number) {
    • return intval($digit);
    • });
    • return array_sum($number);
    • }
Code
Diff
  • def primemaker(x):
        if x<2: return []
        primes = [2]
        for possibleprimes in range(3,x+1, 2):
            for n in range(2,int(possibleprimes**0.5)+1):
                if possibleprimes % n == 0:
                    break
            else:
                primes.append(possibleprimes)
        return primes
    • def primemaker(x):
    • primes = []
    • isprime = True
    • for possibleprimes in range(2,x):
    • for n in range(2,possibleprimes):
    • if possibleprimes % num == 0:
    • isprime = False
    • if isprime:
    • if x<2: return []
    • primes = [2]
    • for possibleprimes in range(3,x+1, 2):
    • for n in range(2,int(possibleprimes**0.5)+1):
    • if possibleprimes % n == 0:
    • break
    • else:
    • primes.append(possibleprimes)
    • print(primes)
    • return primes