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
  • fn disemvowel(string: &str) -> String {
        string.replace(['A','E','I','O','U','a','e','i','o','u'], "")
    }
    • fn disemvowel(string: &str) -> String {
    • string.chars().filter(|&c| !"AEIOUaeiou".contains(c)).collect()
    • string.replace(['A','E','I','O','U','a','e','i','o','u'], "")
    • }
Algorithms
Strings

Fixed the end of the string problem. Now, the char array has a double null terminator character to denote that it has reached the end of the array.

Code
Diff
  • #include <stdlib.h>
    #include <string.h>
    
    /*
      Heap allocate the string and return it.
    */
    
    char* remove_string(const char *input, const int n)
    {
      if (n <= 0 || input == NULL) return NULL;
      for (int c = 1; !(*input == '\0' && *(input + 1) == '\0') && (c < n); (*input == '\0') ? c++ : c, input++);
      return (*input == '\0') ? NULL : strdup(input);
    }
    • #include <stdlib.h>
    • #include <string.h>
    • /*
    • Heap allocate the string and return it.
    • */
    • char* remove_string(const char *input, const int n)
    • {
    • if (n <= 0 || input == NULL) return NULL;
    • for (size_t i = 0, len = 0; i < (size_t)n; i++)
    • {
    • input += len;
    • if ((len = strlen(input) + 1) == 1) return NULL;
    • }
    • return strdup(input);
    • for (int c = 1; !(*input == '\0' && *(input + 1) == '\0') && (c < n); (*input == '\0') ? c++ : c, input++);
    • return (*input == '\0') ? NULL : strdup(input);
    • }
Code
Diff
  • import random
    import time
    def not_even(n):
        pizza_time = time.ctime()
        if n % 2 == 0:
            return 'its not even', pizza_time
        else:
            return 'its still not even', pizza_time
        return pizza_time
    n = random.randint(0, 10000)
     
    print(not_even(n))
    • odd_even=lambda n:int(__import__('requests').get(f'https://api.isevenapi.xyz/api/iseven/{n}/').json()['iseven'])
    • import random
    • import time
    • def not_even(n):
    • pizza_time = time.ctime()
    • if n % 2 == 0:
    • return 'its not even', pizza_time
    • else:
    • return 'its still not even', pizza_time
    • return pizza_time
    • n = random.randint(0, 10000)
    • print(not_even(n))
Code
Diff
  • fn mean(x: &[f64]) -> f64 {
        let x_len_float = x.len() as f64;
        return x.iter().sum::<f64>() / x_len_float;
    }
    
    • fn mean(x: &[u64]) -> u64 {
    • x.iter().sum::<u64>() / x.len() as u64
    • fn mean(x: &[f64]) -> f64 {
    • let x_len_float = x.len() as f64;
    • return x.iter().sum::<f64>() / x_len_float;
    • }

less char -> Short-Circuiting instead of ternary

Code
Diff
  • v='aeiou'
    x=(s,f)=>[...s].map(f).join``
    d=s=>x(s,e=>v[Math.min(6,e)-1]||e)
    n=s=>x(s,e=>v.indexOf(e)+1||e)
    • v='aeiou'
    • x=(s,f)=>[...s].map(f).join``
    • d=s=>x(s,e=>(+e&&e<6?v[e-1]:e))
    • n=s=>x(s,e=>((g=v.indexOf(e)+1)&g?g:e))
    • d=s=>x(s,e=>v[Math.min(6,e)-1]||e)
    • n=s=>x(s,e=>v.indexOf(e)+1||e)

Probably would be considered less clean than the parent,
but also faster by avoiding streams.

Code
Diff
  • #include <string>
    #include <vector>
    
    auto split(const std::string& str, char sep) {
      auto result = std::vector<std::string>{};
      std::string::size_type pos = 0, pos2 = 0;
      
      while ((pos2 = str.find(sep, pos)) != std::string::npos) {
        result.push_back(str.substr(pos, pos2 - pos));
        pos = pos2 + 1;
      }
      result.push_back(str.substr(pos));
      return result;
    }
    
    
    • #include <string>
    • #include <sstream>
    • #include <vector>
    • auto split(const std::string& str, char sep) {
    • auto result = std::vector<std::string>{};
    • auto stream = std::stringstream(str);
    • auto buffer = std::string{};
    • while (std::getline(stream, buffer, sep)) result.emplace_back(buffer);
    • std::string::size_type pos = 0, pos2 = 0;
    • while ((pos2 = str.find(sep, pos)) != std::string::npos) {
    • result.push_back(str.substr(pos, pos2 - pos));
    • pos = pos2 + 1;
    • }
    • result.push_back(str.substr(pos));
    • return result;
    • }

Given an array of n distinct integers in the range [0, n], find the missing integer.

Code
Diff
  • #include <vector>
    #include <numeric>
    using namespace std;
    int missingNumber(vector<int> nums) {
      return (nums.size() * (nums.size() + 1))/2 - accumulate(nums.begin(), nums.end(), 0);
    }
    • #include <vector>
    • #include <algorithm>
    • #include <numeric>
    • using namespace std;
    • int missingNumber(vector<int> nums) {
    • nums.push_back(nums.size());
    • for (int i = 0; i < static_cast<int>(nums.size()); i++) {
    • if (find(nums.begin(), nums.end(), i) == nums.end()) return i;
    • }
    • return nums.size() - 1;
    • return (nums.size() * (nums.size() + 1))/2 - accumulate(nums.begin(), nums.end(), 0);
    • }