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

using datalass

Code
Diff
  • from dataclasses import dataclass
    from decimal import Decimal
    
    @dataclass
    class BMI:
        height: int
        weight: int
        
        @property
        def bmi(self):
            return self.weight / (self.height ** 2)
    
        def calculate_bmi(self):
            return "there is no excess weight" if self.bmi < 25 else "there is excess weight"
    • class BMI:
    • def __init__(self, height, weight):
    • self.height = height
    • self.weight = weight
    • from dataclasses import dataclass
    • from decimal import Decimal
    • @dataclass
    • class BMI:
    • height: int
    • weight: int
    • @property
    • def bmi(self):
    • return self.weight / (self.height ** 2)
    • def calculate_bmi(self):
    • return "there is no excess weight" if self.bmi < 25 else "there is excess weight"

Guess you could like this one too...

Code
Diff
  • #include <algorithm>
    struct ParenAccumulator{
      int count{};
      bool operator()(const char c) {
        count+=(c == '('?1:c == ')'?-1:0);
        return count<0; 
      }
      bool isBalanced() const {return count==0;}
    };
    bool isBalanced(const std::string& s) {
      ParenAccumulator par;
      return std::none_of(s.cbegin(),s.cend(),std::ref(par)) 
          && par.isBalanced(); 
    }
    • #include <algorithm>
    • bool isBalanced(const std::string& s) {
    • struct ParenAccumulator{
    • int count{};
    • if (std::any_of(s.cbegin(),s.cend(),[&](auto c){
    • bool operator()(const char c) {
    • count+=(c == '('?1:c == ')'?-1:0);
    • return count<0;
    • }))
    • return false;
    • return count==0;
    • return count<0;
    • }
    • bool isBalanced() const {return count==0;}
    • };
    • bool isBalanced(const std::string& s) {
    • ParenAccumulator par;
    • return std::none_of(s.cbegin(),s.cend(),std::ref(par))
    • && par.isBalanced();
    • }
Code
Diff
  • spawn_to_range = lambda a, v, r: a[:a.index(v)] + [v] * r + a[a.index(v) + 1:] if v in a else []
    • def spawn_to_range(a, x, n):
    • # return [] if(len(a)==0) else a[0:a.index(x)] + [x]*n + a[a.index(x)+1:]
    • return [*a[0:(i:=a.index(x))],*[x]*n,*(a[j]for j in range(i+1,z))]if(z:=len(a))else[]
    • spawn_to_range = lambda a, v, r: a[:a.index(v)] + [v] * r + a[a.index(v) + 1:] if v in a else []

Use IntSummaryStatistics instead

Code
Diff
  • import static java.util.stream.IntStream.of;
    
    interface HighLow {
        static int[] findLargestAndSmallest(int[] nums) {
            if (nums == null || nums.length == 0) return null;
            var iss = of(nums).summaryStatistics();
            return new int[] {iss.getMin(), iss.getMax()};
        }
    }
    
    • import static java.util.stream.IntStream.of;
    • interface HighLow {
    • static int[] findLargestAndSmallest(int[] nums) {
    • if (nums == null || nums.length == 0) return null;
    • int[] sorted = of(nums).sorted().toArray();
    • return new int[] {sorted[0], sorted[sorted.length - 1]};
    • }
    • static int[] findLargestAndSmallest(int[] nums) {
    • if (nums == null || nums.length == 0) return null;
    • var iss = of(nums).summaryStatistics();
    • return new int[] {iss.getMin(), iss.getMax()};
    • }
    • }
Code
Diff
  • find_multiples_of_4_and_6=lambda n:[i for i in range(n) if not (i%4 and i%6)]
    • def find_multiples_of_4_and_6(n):
    • return (i for i in range(n) if not (i%4 and i%6))
    • find_multiples_of_4_and_6=lambda n:[i for i in range(n) if not (i%4 and i%6)]