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
  • binary=lambda n: '{:b}'.format(n)
    • def binary(n: int) -> str:
    • return f'{n:b}'
    • binary=lambda n: '{:b}'.format(n)
Fundamentals
Strings
Code
Diff
  • #include <string>
    #include <fmt/ranges.h>
    
    auto digest(const std::string& param) {
      if (param.empty()) return param; // Oh... should check there !!
      return fmt::format("{}", fmt::join(param, " "));
    }
    • #include <string>
    • #include <numeric>
    • #include <fmt/ranges.h>
    • auto digest(const std::string& param) {
    • if (param.empty()) return param; // Oh... should check there !!
    • return std::accumulate(std::next(param.cbegin()),param.cend(),
    • std::string(1,param[0]), // Char initializer
    • [](auto &s, auto c) {
    • return s+std::string{{' ',c}}; // initializer_list string initializer
    • });
    • return fmt::format("{}", fmt::join(param, " "));
    • }

The main change is that the file attribute is initialized to None instead of being conditionally set to an open file. Instead, the file is opened in the write_to_file method if it hasn't been opened yet. This makes the code more explicit and easier to reason about. Additionally, I added some whitespace and changed the indentation to conform to PEP 8 style guidelines.

Code
Diff
  • class Solution:
        def __init__(self, data, filename='kumite776.txt', preopen=False):
            self.data = data
            self.filename = filename
            self.file = None
            if preopen:
                self.file = open(self.filename, 'w')
        
        def write_to_file(self):
            if not self.file:
                self.file = open(self.filename, 'w')
            self.file.write(self.data)
    
    • class Solution:
    • def __init__(self, data, filename='kumite776.txt', preopen=False):
    • self.data = data
    • self.filename = filename
    • self.file = open(self.filename, 'w') if preopen else None
    • self.file = None
    • if preopen:
    • self.file = open(self.filename, 'w')
    • def write_to_file(self):
    • if not self.file: self.file = open(self.filename, 'w')
    • if not self.file:
    • self.file = open(self.filename, 'w')
    • self.file.write(self.data)

made more test cases so that the idiots who write one-line regex scripts need to write more to deal with Bool, Int, and NoneType :3

Code
Diff
  • knight_move3d=lambda p:[*set(map(abs,p))]in([0,1,2],[0])
    • knight_move3d=lambda pos:[*set(map(abs,pos))]in([0,1,2],[0])
    • knight_move3d=lambda p:[*set(map(abs,p))]in([0,1,2],[0])

Now sorts intergers with length greater than 1 in the array.

Code
Diff
  • def greatest(num):
        return int(''.join(sorted([str(y) for x in [[int(z) for z in str(n)] for n in num] for y in x], reverse=True)))
    • def greatest(lst):
    • output = ''
    • c = [0] * (max(lst) + 1)
    • for i in lst:
    • c[i] += 1
    • s = []
    • for i in reversed(range(len(c))):
    • while c[i] != 0:
    • c[i] -= 1
    • s.append(i)
    • for n in s:
    • output += f'{n}'
    • return int(output)
    • def greatest(num):
    • return int(''.join(sorted([str(y) for x in [[int(z) for z in str(n)] for n in num] for y in x], reverse=True)))