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.
fn digit_sum(number: i128) -> u32 { number .to_string() .chars() .map(|c| c.to_digit(10)) .flatten() .sum() }
def digit_sum(number: int) -> int:return(sum([int(num) for num in str(abs(number))]))- fn digit_sum(number: i128) -> u32 {
- number
- .to_string()
- .chars()
- .map(|c| c.to_digit(10))
- .flatten()
- .sum()
- }
#[cfg(test)] mod tests { use super::*; #[test] fn test_sums() { assert_eq!(digit_sum(10000000000000000000000000000), 1); assert_eq!(digit_sum(55001), 11); assert_eq!(digit_sum(104), 5); assert_eq!(digit_sum(0), 0); assert_eq!(digit_sum(-1204), 7); } }
from unittest import TestCasefrom solution import digit_sumimport codewars_test as testfrom solution import digit_sum@test.describe('Tests')def tests():@test.it('Test Cases')def test_sums():test.assert_equals(digit_sum(10000000000000000000000000000),1)test.assert_equals(digit_sum(55001),11)test.assert_equals(digit_sum(104),5)test.assert_equals(digit_sum(0),0)test.assert_equals(digit_sum(-1204),7)- #[cfg(test)]
- mod tests {
- use super::*;
- #[test]
- fn test_sums() {
- assert_eq!(digit_sum(10000000000000000000000000000), 1);
- assert_eq!(digit_sum(55001), 11);
- assert_eq!(digit_sum(104), 5);
- assert_eq!(digit_sum(0), 0);
- assert_eq!(digit_sum(-1204), 7);
- }
- }
def sum(*args) -> int: black_list = [str(type("")), str(type({}))] sum_of_args = 0 for i in args: if str(type(i)) in black_list: exit(1) else: if str(type(i)) == str(type([])): for k in range(len(i)): sum_of_args += i[k] else: sum_of_args += i return sum_of_args
def sum(arr):var = 0for i in arr:var += ireturn var- def sum(*args) -> int:
- black_list = [str(type("")), str(type({}))]
- sum_of_args = 0
- for i in args:
- if str(type(i)) in black_list:
- exit(1)
- else:
- if str(type(i)) == str(type([])):
- for k in range(len(i)):
- sum_of_args += i[k]
- else:
- sum_of_args += i
- return sum_of_args
Minus 7
How many times can you subtract 7 from a given number?
Examples
numMinusSeven(1000) === 143;
numMinusSeven(100) === 15;
numMinusSeven(10) === 2;
function numMinusSeven(num) { return Math.ceil(num / 7) }
- function numMinusSeven(num) {
let arr = []while (num > 0) {num -= 7arr.push(num)}return arr.length- return Math.ceil(num / 7)
- }
const chai = require("chai"); const assert = chai.assert; chai.config.truncateThreshold = 0; const Test = require("@codewars/test-compat"); describe("Minus 7 test cases", function() { it("should test for 1000", function() { Test.assertEquals(numMinusSeven(1000), 143); }); it("should test for 100", function() { Test.assertEquals(numMinusSeven(100), 15); }); it("should test for 10", function() { Test.assertEquals(numMinusSeven(10), 2); }); });
- const chai = require("chai");
- const assert = chai.assert;
- chai.config.truncateThreshold = 0;
- const Test = require("@codewars/test-compat");
describe("Test", function() {- describe("Minus 7 test cases", function() {
- it("should test for 1000", function() {
- Test.assertEquals(numMinusSeven(1000), 143);
- });
it("should test for 100", function() {Test.assertEquals(numMinusSeven(100), 15);});it("should test for 10", function() {Test.assertEquals(numMinusSeven(10), 2);});- it("should test for 100", function() {
- Test.assertEquals(numMinusSeven(100), 15);
- });
- it("should test for 10", function() {
- Test.assertEquals(numMinusSeven(10), 2);
- });
- });
export type BmiProps = { height: number; weight: number; }; export type CalculateBmiProps = BmiProps & { system: "metric" | "imperial"; }; export const imperialToMetric = ({ height, weight }: BmiProps): BmiProps => { return { height: height * 0.3048, weight: weight * 0.453592 }; }; export const calculateBmi = ( { height, weight, system }: CalculateBmiProps, ): number => { const { height: h, weight: w } = system === "imperial" ? imperialToMetric({ height, weight }) : { height, weight }; return Math.round((w / (h ** 2)) * 100) / 100; };
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);}- export type BmiProps = {
- height: number;
- weight: number;
- };
this._weight = weight;}get bmi(): number {return Number((this._weight / Math.pow(this._height, 2)).toFixed(2));}- export type CalculateBmiProps = BmiProps & {
- system: "metric" | "imperial";
- };
- export const imperialToMetric = ({ height, weight }: BmiProps): BmiProps => {
- return { height: height * 0.3048, weight: weight * 0.453592 };
- };
- export const calculateBmi = (
- { height, weight, system }: CalculateBmiProps,
- ): number => {
- const { height: h, weight: w } = system === "imperial"
- ? imperialToMetric({ height, weight })
- : { height, weight };
calculateBMI(): string {return `there is ${this.bmi < 25 ? 'no ' : ''}excess weight`;}}- return Math.round((w / (h ** 2)) * 100) / 100;
- };
import { assert } from "chai"; import { calculateBmi } from "./solution"; describe('BMI Calculator', function() { it('BMI calculates correctly', function() { assert.equal(calculateBmi({ height: 6, weight: 160, system:'imperial' }), 21.7); assert.equal(calculateBmi({ height: 3, weight: 160, system:'metric' }), 17.78); }); });
// See https://www.chaijs.com for how to use Chai.- import { assert } from "chai";
import BMI from "./solution";const BMI_OK = "there is no excess weight";const BMI_NOT_OK = "there is excess weight";- import { calculateBmi } from "./solution";
- describe('BMI Calculator', function() {
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);- it('BMI calculates correctly', function() {
- assert.equal(calculateBmi({ height: 6, weight: 160, system:'imperial' }), 21.7);
- assert.equal(calculateBmi({ height: 3, weight: 160, system:'metric' }), 17.78);
- });
- });
pub fn bool_check(bools: [bool; 3]) -> bool { bools.into_iter().filter(|&b| b).count() >= 2 }
public class Kumite {public static boolean boolCheck(boolean[] bools) {return bools[0] ? bools[1] || bools[2] : bools[1] && bools[2];}- pub fn bool_check(bools: [bool; 3]) -> bool {
- bools.into_iter().filter(|&b| b).count() >= 2
- }
#[cfg(test)] mod tests { use super::bool_check; #[test] fn test_true() { assert!(bool_check([true, true, true])); assert!(bool_check([true, true, false])); assert!(bool_check([true, false, true])); assert!(bool_check([false, true, true])); } #[test] fn test_false() { assert!(!bool_check([false, false, false])); assert!(!bool_check([true, false, false])); assert!(!bool_check([false, true, false])); assert!(!bool_check([false, false, true])); } }
import org.junit.jupiter.api.Test;import static org.junit.jupiter.api.Assertions.assertEquals;// TODO: Replace examples and use TDD by writing your own testsclass SolutionTest {@Testvoid test0True() {boolean[] bools = new boolean[3];assertEquals(false, Kumite.boolCheck(bools));- #[cfg(test)]
- mod tests {
- use super::bool_check;
- #[test]
- fn test_true() {
- assert!(bool_check([true, true, true]));
- assert!(bool_check([true, true, false]));
- assert!(bool_check([true, false, true]));
- assert!(bool_check([false, true, true]));
- }
@Testvoid test1True() {boolean[] bools = new boolean[3];for(int i = 0; i < 3; i++) {for(int j = 0; j < 3; j++) {bools[j] = false;}bools[i] = true;assertEquals(false, Kumite.boolCheck(bools));}- #[test]
- fn test_false() {
- assert!(!bool_check([false, false, false]));
- assert!(!bool_check([true, false, false]));
- assert!(!bool_check([false, true, false]));
- assert!(!bool_check([false, false, true]));
- }
@Testvoid test2True() {boolean[] bools = new boolean[3];for(int i = 0; i < 3; i++) {for(int j = 0; j < 3; j++) {bools[j] = true;}bools[i] = false;assertEquals(true, Kumite.boolCheck(bools));}}@Testvoid test3True() {boolean[] bools = new boolean[]{true, true, true};assertEquals(true, Kumite.boolCheck(bools));}}- }
Description:
Function that checks if two char arrays contain a common item between
them.
using System.Collections.Generic; using System.Linq; public class Kata { /// <summary> /// Checks if two char arrays contain at least one common item. /// </summary> /// <param name="a">First char array</param> /// <param name="b">Second char array</param> /// <returns>True if the arrays have at least one common item, false otherwise</returns> public static bool ContainsCommonItem(char[] a, char[] b) { return a == null || b == null ? false : a.Intersect(b).Any(); } }
- using System.Collections.Generic;
- using System.Linq;
- public class Kata
- {
- /// <summary>
- /// Checks if two char arrays contain at least one common item.
- /// </summary>
- /// <param name="a">First char array</param>
- /// <param name="b">Second char array</param>
- /// <returns>True if the arrays have at least one common item, false otherwise</returns>
- public static bool ContainsCommonItem(char[] a, char[] b)
- {
// If either input array is null, return falseif (a == null || b == null) return false;return a.Intersect(b).Any();- return a == null || b == null ? false : a.Intersect(b).Any();
- }
- }