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

just made it shorter

Code
Diff
  • public class ReverseString {
      public static String reverseString(String word) {
        StringBuilder result = new StringBuilder(word);
        return result.reverse().toString();
        }
    }
    • public class ReverseString {
    • public static String reverseString(String word) {
    • StringBuilder result = new StringBuilder();
    • result.append(word);// adds the word to the string
    • result.reverse();// you know REVERSES it
    • return result.toString();
    • StringBuilder result = new StringBuilder(word);
    • return result.reverse().toString();
    • }
    • }
Arrays
Code
Diff
  • #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <cassert>
    
    int unique_sum(const std::vector<int>& n) {
      auto nums = n;
      std::sort(nums.begin(), nums.end(), [](int a, int b) {
        return a < b;
      });
      int sum = 0;
      for(size_t i = 0; i < nums.size(); i++) {
        if(nums[i] == nums[i+1] || nums[i] == nums[i-1]) {
          continue;
        } else {
          sum += nums[i];
        }
      }
      return sum;
    }
    • #include <iostream>
    • #include <vector>
    • #include <unordered_map>
    • #include <algorithm>
    • #include <cassert>
    • int unique_sum(const std::vector<int>& nums) {
    • std::unordered_map<int, int> hashMap;
    • for (int i = 0; i < nums.size(); i++) {
    • if (hashMap.find(nums[i]) == hashMap.end()) {
    • hashMap[nums[i]] = nums[i];
    • int unique_sum(const std::vector<int>& n) {
    • auto nums = n;
    • std::sort(nums.begin(), nums.end(), [](int a, int b) {
    • return a < b;
    • });
    • int sum = 0;
    • for(size_t i = 0; i < nums.size(); i++) {
    • if(nums[i] == nums[i+1] || nums[i] == nums[i-1]) {
    • continue;
    • } else {
    • hashMap[nums[i]] = 0;
    • sum += nums[i];
    • }
    • }
    • int sum = 0;
    • for (auto i: hashMap) {
    • sum = sum + hashMap[i.first];
    • }
    • return sum;
    • }
Code
Diff
  • import os
    
    
    class BitBlender:
        """BitBlender class"""
    
        def __init__(self, target_file, num=7, deletion=False):
            self.target_file = target_file
            self.num = num  # number of times to overwrite file   
            self.deletion = deletion    
            self.file_size = os.path.getsize(self.target_file)
            if os.path.exists(self.target_file):
                self.file_size = os.path.getsize(self.target_file)
            else:
                raise FileNotFoundError(f"The file '{self.target_file}' does not exist.")
                
    
        def execute(self):
            try:
                # Overwrite the file with random data
                with open(self.target_file, "wb") as f:
                    # Repeat this process num times
                    for i in range(self.num):
                        f.write(os.urandom(self.file_size))            
                # If you choose to delete: 
                if self.deletion:
                    os.remove(self.target_file)            
            except Exception as e:
                print(f"Error: {e}")
    • import os
    • class BitBlender:
    • """BitBlender class"""
    • def __init__(self, target_file, num=7, deletion=False):
    • self.target_file = target_file
    • self.num = num # number of times to overwrite file
    • self.deletion = deletion
    • self.file_size = os.path.getsize(self.target_file)
    • if os.path.exists(self.target_file):
    • self.file_size = os.path.getsize(self.target_file)
    • else:
    • raise FileNotFoundError(f"The file '{self.target_file}' does not exist.")
    • def execute(self):
    • pass
    • try:
    • # Overwrite the file with random data
    • with open(self.target_file, "wb") as f:
    • # Repeat this process num times
    • for i in range(self.num):
    • f.write(os.urandom(self.file_size))
    • # If you choose to delete:
    • if self.deletion:
    • os.remove(self.target_file)
    • except Exception as e:
    • print(f"Error: {e}")
  • Trimmed down the function name for minimum characters
Code
Diff
  • ClosestToZero=lambda n:type("",(),{"e":lambda v=min(n,key=abs,default=0):dict(zip(n,n)).get(abs(v),v),"n":n})
    • ClosestToZero=lambda n:type("",(),{"execute":lambda v=min(n,key=abs,default=0):dict(zip(n,n)).get(abs(v),v),"n":n})
    • ClosestToZero=lambda n:type("",(),{"e":lambda v=min(n,key=abs,default=0):dict(zip(n,n)).get(abs(v),v),"n":n})
  • Botched the indents
Code
Diff
  • class MaxDigit:
     def __init__(s, n):s.n = n
     def execute(s): return int(''.join(sorted(str(s.n), reverse=True)))
    • class MaxDigit:
    • def __init__(s, n):
    • s.n = n
    • def execute(s):
    • return int(''.join(sorted(str(s.n), reverse=True)))
    • def __init__(s, n):s.n = n
    • def execute(s): return int(''.join(sorted(str(s.n), reverse=True)))