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
  • def find_multiples(n):
        return sum({*range(4, n, 4), *range(6, n, 6)})
    • def find_multiples(n):
    • return sum({num for num in range(4, n, 4)} | {num for num in range(6, n, 6)})
    • return sum({*range(4, n, 4), *range(6, n, 6)})
Strings
Parsing
Code
Diff
  • function stripEnds(s, prefix, suffix) {
      return s.replace(new RegExp(`[${prefix}${suffix}]`, 'gi'), '');
    }
    • function stripEnds(s, prefix, suffix) {
    • return s.replace(prefix, '').replace(suffix, '');
    • return s.replace(new RegExp(`[${prefix}${suffix}]`, 'gi'), '');
    • }
Code
Diff
  • Unit Kata;
    interface
    
    function IsLeap(year: integer): boolean;
    
    implementation
      
    function IsLeap(year: integer): boolean;
    begin
      result := (year mod 400 = 0) or ((year mod 4 = 0) and (year mod 100 <> 0));
    end;
    
    end.
    • bool isLeap(int year) {
    • return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
    • }
    • Unit Kata;
    • interface
    • function IsLeap(year: integer): boolean;
    • implementation
    • function IsLeap(year: integer): boolean;
    • begin
    • result := (year mod 400 = 0) or ((year mod 4 = 0) and (year mod 100 <> 0));
    • end;
    • end.

Which years are leap years?
To be a leap year, the year number must be divisible by four – except for end-of-century years, which must be divisible by 400. This means that the year 2000 was a leap year, although 1900 was not. 2020, 2024 and 2028 are all leap years.

Code
Diff
  • using System;
    
    public class LeapYears
    {
      public static bool IsLeapYear(int year)
      {
        // End of a century must be divisible by 400
        if(year.ToString().EndsWith("00") && year % 400 == 0)
          return true;
        // Not the end of a century must be divisible by 4
        else if(!year.ToString().EndsWith("00") && year % 4 == 0)
          return true;
        else
          return false;
      }
    }
    • using System;
    • public class LeapYears
    • {
    • // Works but hurts
    • public static bool IsLeapYear(int y) => (y % 400 == 0) ? true : (y % 100 == 0 && y % 400 != 0) ? false : (y % 4 == 0 && y % 100 != 0) ? true : false;
    • public static bool IsLeapYear(int year)
    • {
    • // End of a century must be divisible by 400
    • if(year.ToString().EndsWith("00") && year % 400 == 0)
    • return true;
    • // Not the end of a century must be divisible by 4
    • else if(!year.ToString().EndsWith("00") && year % 4 == 0)
    • return true;
    • else
    • return false;
    • }
    • }

Fork from Python BMI calculator made via typescript.

Code
Diff
  • export default class BMI {
      private _height: number;
      private _weight: number;
      
      constructor(weight: number, height: number) {
        this._height = height;
        this._weight = weight;
      }
      
      set height(height: number) {
        if (height <= 0) {
          const invalidValueError = new Error('Invalid value');
          console.error(invalidValueError);
        }
        this._height = height;
      }
      
      set width(weight: number) {
        if (weight <= 0) {
          const invalidValueError = new Error('Invalid value');
          console.error(invalidValueError);
        }
    
        this._weight = weight;
      }
      
      get bmi(): number {
        return Number((this._weight / Math.pow(this._height, 2)).toFixed(2));
      }
      
      calculateBMI(): string {
        return `there is ${this.bmi < 25 ? 'no ' : ''}excess weight`;
      }
    }
    • from dataclasses import dataclass
    • export default class BMI {
    • private _height: number;
    • private _weight: number;
    • constructor(weight: number, height: number) {
    • this._height = height;
    • this._weight = weight;
    • }
    • set height(height: number) {
    • if (height <= 0) {
    • const invalidValueError = new Error('Invalid value');
    • console.error(invalidValueError);
    • }
    • this._height = height;
    • }
    • set width(weight: number) {
    • if (weight <= 0) {
    • const invalidValueError = new Error('Invalid value');
    • console.error(invalidValueError);
    • }
    • @dataclass
    • class BMI:
    • height: float
    • weight: float
    • @property
    • def bmi(self) -> float:
    • return self.weight / (self.height ** 2)
    • def calculate_bmi(self) -> str:
    • return f"there {'is no' if self.bmi < 25 else 'is'} excess weight"
    • this._weight = weight;
    • }
    • get bmi(): number {
    • return Number((this._weight / Math.pow(this._height, 2)).toFixed(2));
    • }
    • calculateBMI(): string {
    • return `there is ${this.bmi < 25 ? 'no ' : ''}excess weight`;
    • }
    • }