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
  • //Сдобникова
    function sumNechet(a, b) {
      var i, sum = 0;
      for (i=0; i<=b; i++){
        if (i % 2 === 1) 
          sum += i;
        }
      return sum;  
    }
    
    
    • //Сдобникова
    • function sumNechet(a, b) {
    • var i, sum = 0;
    • for (i=0; i<=b; i++){
    • if (i % 2 === 1)
    • sum += i;
    • }
    • return sum;
    • }
    • function нечетное(число) {
    • }
Code
Diff
  • const cinema_auditorium = (spisok2D, ryad) => {
      let soldTickets = 0;
    
      if (spisok2D && ryad >= 0 && ryad < spisok2D.length) {
        for (let seat of spisok2D[ryad]) {
          if (seat === 1) {
            soldTickets++;
          }
        }
      }
      return soldTickets;
    }
    • const cinema_auditorium = (spisok2D,ryad)=> {
    • console.log(spisok2D,ryad)
    • return 3
    • const cinema_auditorium = (spisok2D, ryad) => {
    • let soldTickets = 0;
    • if (spisok2D && ryad >= 0 && ryad < spisok2D.length) {
    • for (let seat of spisok2D[ryad]) {
    • if (seat === 1) {
    • soldTickets++;
    • }
    • }
    • }
    • return soldTickets;
    • }
Code
Diff
  • function rps(p1, p2) {
      let arr = ['rock','paper','scissors']
      return p1 == p2 ? 'Draw!' : 
        p1 == arr[0] && p2 == arr[2] || 
        p1 == arr[2] && p2 == arr[1] || 
        p1 == arr[1] && p2 == arr[0] ? 'Player 1 won!' : 'Player 2 won!';
    }
    
    • function rps(player1, player2) {
    • return player1 == player2 ? 'Draw!' :
    • player1 == 'rock' && player2 == 'scissors' ||
    • player1 == 'scissors' && player2 == 'paper' ||
    • player1 == 'paper' && player2 == 'rock' ? 'Player 1 won!' : 'Player 2 won!';
    • function rps(p1, p2) {
    • let arr = ['rock','paper','scissors']
    • return p1 == p2 ? 'Draw!' :
    • p1 == arr[0] && p2 == arr[2] ||
    • p1 == arr[2] && p2 == arr[1] ||
    • p1 == arr[1] && p2 == arr[0] ? 'Player 1 won!' : 'Player 2 won!';
    • }

Algebraic solution.
The sum collector on the range iterator optimizes away the iteration, resulting in an O(1) solution.

Code
Diff
  • fn find_multiples(n: u32) -> u32 {
        if n == 0 { return 0 }
        let sum = |f| f * (1..=((n-1)/f)).sum::<u32>();
        sum(4) + sum(6) - sum(12)
    }
    • def find_multiples(n):
    • total = 0
    • for i in range(0, n, 2):
    • if i % 4 == 0 or i % 6 == 0:
    • total += i
    • return total
    • fn find_multiples(n: u32) -> u32 {
    • if n == 0 { return 0 }
    • let sum = |f| f * (1..=((n-1)/f)).sum::<u32>();
    • sum(4) + sum(6) - sum(12)
    • }
Mathematics

Problem: Subtract Seven Until Zero

Write a function numMinusSeven(num) that takes a number as an argument. The function should subtract seven from the given number until the result is less than or equal to zero. The function should return the number of times seven could be subtracted.

For example:

If the given number is 1000, the function should return 143 because you can subtract seven 143 times before getting a number less than or equal to zero.
If the given number is 100, the function should return 15.
If the given number is 10, the function should return 2.

Code
Diff
  • function numMinusSeven(num) {
      return Math.ceil(num / 7);
    }
    • function numMinusSeven(num) {
    • let arr = []
    • while (num > 0) {
    • num -= 7
    • arr.push(num)
    • }
    • return arr.length
    • }
    • return Math.ceil(num / 7);
    • }

nothing

Code
Diff
  • print("hello {}".format(len("Word")))
    • print("hello")
    • print(2+5)
    • print("hello {}".format(len("Word")))
Code
Diff
  • def sum(arr):
        if not arr:
            return 0
        else:
            return arr[0] + sum(arr[1:])
        
    • def sum(arr):
    • result = 0
    • for i in arr:
    • result += i
    • return result
    • if not arr:
    • return 0
    • else:
    • return arr[0] + sum(arr[1:])
Fundamentals
Code
Diff
  • fn number_print(x: u8) -> u128 {
        (1..=x)
            .chain((1..x).rev())
            .map(|n| n.to_string())
            .collect::<String>()
            .parse()
            .unwrap()
    }
    • def numberprint(x):
    • accending = list(range(1, x + 1))
    • descending = list(range(x-1, 0, -1))
    • newlist = accending + descending
    • strings = [str(integer) for integer in newlist]
    • a_string = "".join(strings)
    • an_integer = int(a_string)
    • return an_integer
    • fn number_print(x: u8) -> u128 {
    • (1..=x)
    • .chain((1..x).rev())
    • .map(|n| n.to_string())
    • .collect::<String>()
    • .parse()
    • .unwrap()
    • }

The amends I've made ensure that the setter methods are used in the constructor. They weren't used at all and the name of the "set weight" method was "set width".

Here rather than writing the errors to console and continuing with the code we throw an error.

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) {
          throw new Error('Invalid value for height');
        }
        this._height = height;
      }
      
      set weight(weight: number) {
        if (weight <= 0) {
          throw new Error('Invalid value for 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`;
      }
    }
    • export default class BMI {
    • private _height: number;
    • private _weight: number;
    • private _height!: number;
    • private _weight!: number;
    • constructor(weight: number, height: number) {
    • this._height = height;
    • this._weight = weight;
    • this.height = height;
    • this.weight = weight;
    • }
    • set height(height: number) {
    • if (height <= 0) {
    • const invalidValueError = new Error('Invalid value');
    • console.error(invalidValueError);
    • throw new Error('Invalid value for height');
    • }
    • this._height = height;
    • }
    • set width(weight: number) {
    • set weight(weight: number) {
    • if (weight <= 0) {
    • const invalidValueError = new Error('Invalid value');
    • console.error(invalidValueError);
    • throw new Error('Invalid value for 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`;
    • }
    • }