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
  • #include <string>
    #include <string_view>
    #include <algorithm>
    
    using namespace std;
    
    string fun(string_view input)
    {
      string result;
      result.reserve(input.size());
      transform(input.cbegin(), input.cend(), back_inserter(result), [](unsigned char c) -> char {
        return toupper(c);
      });
      
      return result;
    }
    • #include <string>
    • #include <string_view>
    • #include <algorithm>
    • std::string fun(std::string_view input)
    • using namespace std;
    • string fun(string_view input)
    • {
    • std::string result;
    • string result;
    • result.reserve(input.size());
    • std::transform(input.cbegin(), input.cend(), std::back_inserter(result), [](unsigned char c) -> char {
    • return std::toupper(c);
    • transform(input.cbegin(), input.cend(), back_inserter(result), [](unsigned char c) -> char {
    • return toupper(c);
    • });
    • return result;
    • }
Code
Diff
  • import random
    from random import randrange
    
    
    def slow_sum(lst):
        
        if lst:
            s = sum(lst)
        else:
            s = 0
        randrange(s-1, s+1)
        while True:
            temp =  randrange(s-10000, s+10000)
            if temp == s: 
                return temp
        
    • import random
    • from random import randrange
    • def slow_sum(lst):
    • sum = 0
    • for num in lst:
    • sum += num
    • return sum
    • if lst:
    • s = sum(lst)
    • else:
    • s = 0
    • randrange(s-1, s+1)
    • while True:
    • temp = randrange(s-10000, s+10000)
    • if temp == s:
    • return temp
Arrays
Code
Diff
  • #include <vector>
    #include <unordered_map>
    #include <numeric>
    
    int unique_sum(const std::vector<int>& n)
    {
      std::unordered_map<int,int> frequencies;
      for (auto i : n) 
          ++frequencies[i]; 
      
      return std::accumulate(begin(n), end(n), 0, [&](auto sum, auto i){
        return frequencies[i] == 1 ? sum + i : sum;
      });
    }
    • #include <vector>
    • #include <map>
    • #include <unordered_map>
    • #include <numeric>
    • int unique_sum(const std::vector<int>& n) {
    • auto histogram=[&](){
    • std::map<int,int> nums;
    • for (auto i:n) ++nums[i];
    • return nums;
    • };
    • int unique_sum(const std::vector<int>& n)
    • {
    • std::unordered_map<int,int> frequencies;
    • for (auto i : n)
    • ++frequencies[i];
    • int sum=0;
    • for (auto [k,c]:histogram()) if (c==1) sum+=k;
    • return sum;
    • return std::accumulate(begin(n), end(n), 0, [&](auto sum, auto i){
    • return frequencies[i] == 1 ? sum + i : sum;
    • });
    • }

I created a single parameterized test to avoid redundant tests for the same output function without additional logic.

Code
Diff
  • #Onelined again...
    def above_two(arg): return (arg < 2) or (arg >= 2)
    • def above_two(arg):
    • return (arg < 2) or (arg >= 2)
    • #Onelined again...
    • def above_two(arg): return (arg < 2) or (arg >= 2)