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.
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;
- }
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.
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 = 0for i in range(0, n, 2):if i % 4 == 0 or i % 6 == 0:total += ireturn 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)
- }
#[test] fn test() { assert_eq!(find_multiples(20), 64); assert_eq!(find_multiples(35), 198); assert_eq!(find_multiples(120), 2340); }
import codewars_test as testimport solution # or from solution import example@test.describe("Example")def test_group():@test.it("test case")def test_case():test.assert_equals(find_multiples(20), 64)test.assert_equals(find_multiples(35), 198)test.assert_equals(find_multiples(120), 2340)- #[test]
- fn test() {
- assert_eq!(find_multiples(20), 64);
- assert_eq!(find_multiples(35), 198);
- assert_eq!(find_multiples(120), 2340);
- }
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.
nothing
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 + descendingstrings = [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()
- }
#[test] fn test() { assert_eq!(number_print(1), 1); assert_eq!(number_print(2), 121); assert_eq!(number_print(10), 12345678910987654321); assert_eq!(number_print(14), 123456789101112131413121110987654321); }
import codewars_test as testfrom solution import numberprint@test.describe("Fixed Tests")def basic_tests():@test.it("Fixed tests")def fixed_tests():test.assert_equals(numberprint(1), 1)test.assert_equals(numberprint(2), 121)test.assert_equals(numberprint(10), 12345678910987654321)- #[test]
- fn test() {
- assert_eq!(number_print(1), 1);
- assert_eq!(number_print(2), 121);
- assert_eq!(number_print(10), 12345678910987654321);
- assert_eq!(number_print(14), 123456789101112131413121110987654321);
- }
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.
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`;
- }
- }
// See https://www.chaijs.com for how to use Chai. import { expect, assert } from "chai"; import BMI from "./solution"; const BMI_OK = "there is no excess weight"; const BMI_NOT_OK = "there is excess weight"; describe('BMI Calculator', function() { it('verifies valid input', function() { expect(() => new BMI(1, 1)).to.not.throw(); expect(() => new BMI(0, 1)).to.throw('Invalid value for weight'); expect(() => new BMI(1, 0)).to.throw('Invalid value for height'); }); it('BMI is ok testing', function() { assert.strictEqual(new BMI(55, 1.60).calculateBMI(), BMI_OK); assert.strictEqual(new BMI(50, 1.75).calculateBMI(), BMI_OK); assert.strictEqual(new BMI(77, 1.76).calculateBMI(), BMI_OK); }); it('BMI is not ok testing', function() { assert.strictEqual(new BMI(75, 1.70).calculateBMI(), BMI_NOT_OK); assert.strictEqual(new BMI(100, 1.70).calculateBMI(), BMI_NOT_OK); }); });
- // See https://www.chaijs.com for how to use Chai.
import { assert } from "chai";- import { expect, assert } from "chai";
- import BMI from "./solution";
- const BMI_OK = "there is no excess weight";
- const BMI_NOT_OK = "there is excess weight";
- describe('BMI Calculator', function() {
- it('verifies valid input', function() {
- expect(() => new BMI(1, 1)).to.not.throw();
- expect(() => new BMI(0, 1)).to.throw('Invalid value for weight');
- expect(() => new BMI(1, 0)).to.throw('Invalid value for height');
- });
- it('BMI is ok testing', function() {
- assert.strictEqual(new BMI(55, 1.60).calculateBMI(), BMI_OK);
- assert.strictEqual(new BMI(50, 1.75).calculateBMI(), BMI_OK);
- assert.strictEqual(new BMI(77, 1.76).calculateBMI(), BMI_OK);
- });
- it('BMI is not ok testing', function() {
- assert.strictEqual(new BMI(75, 1.70).calculateBMI(), BMI_NOT_OK);
- assert.strictEqual(new BMI(100, 1.70).calculateBMI(), BMI_NOT_OK);
- });
- });