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.
Here is one in Python, rounding up to the nearest hundredth.
def final_price(price): vat = 0.1 lux = 0.3 return round(price*(1+vat+lux),2) if price >= 1000 else round(price*(1+vat),2)
function finalPrice(price) {var vat = 0.1var lux = 0.3if(price >= 1000) {return Math.floor(price * (1+vat+lux))} else {return Math.floor(price * (1+vat))}}- def final_price(price):
- vat = 0.1
- lux = 0.3
- return round(price*(1+vat+lux),2) if price >= 1000 else round(price*(1+vat),2)
# test.assert_equals(actual, expected, [optional] message) @test.describe("These are your Test results") def test_group(): @test.it("test case") def test_case(): #basic tests test.assert_equals(final_price(100), 110); test.assert_equals(final_price(900), 990); test.assert_equals(final_price(2000), 2800); #edge_cases test.assert_equals(final_price(1000), 1400); test.assert_equals(final_price(999), 1098.9); #rounding test.assert_equals(final_price(101), 111.1);
const chai = require("chai");const assert = chai.assert;const Test = require("@codewars/test-compat");describe("Solution", function() {it("Final Price", function() {assert.equal(finalPrice(100), 110);assert.equal(finalPrice(100), 110);assert.equal(finalPrice(1000), 1400);assert.equal(finalPrice(900), 990);assert.equal(finalPrice(2000), 2800);});});- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("These are your Test results")
- def test_group():
- @test.it("test case")
- def test_case():
- #basic tests
- test.assert_equals(final_price(100), 110);
- test.assert_equals(final_price(900), 990);
- test.assert_equals(final_price(2000), 2800);
- #edge_cases
- test.assert_equals(final_price(1000), 1400);
- test.assert_equals(final_price(999), 1098.9);
- #rounding
- test.assert_equals(final_price(101), 111.1);
std::string rps(const std::string p1, const std::string p2) { enum shape { rock = 1 << 0, paper = 1 << 1, scissors = 1 << 2, lizard = 1 << 3, spock = 1 << 4, beaten_by_rock = shape::scissors | shape::lizard, beaten_by_paper = shape::spock | shape::rock, beaten_by_scissors = shape::paper | shape::lizard, beaten_by_lizard = shape::spock | shape::paper, beaten_by_spock = shape::scissors | shape::rock }; typedef std::pair<shape, shape> shape_info; static std::map<std::string, shape_info> shapes; if (shapes.empty()) { shapes.insert(std::make_pair("rock", std::make_pair(shape::rock, shape::beaten_by_rock))); shapes.insert(std::make_pair("paper", std::make_pair(shape::paper, shape::beaten_by_paper))); shapes.insert(std::make_pair("scissors", std::make_pair(shape::scissors, shape::beaten_by_scissors))); shapes.insert(std::make_pair("lizard", std::make_pair(shape::lizard, shape::beaten_by_lizard))); shapes.insert(std::make_pair("spock", std::make_pair(shape::spock, shape::beaten_by_spock))); } assert(shapes.find(p1) != shapes.end()); assert(shapes.find(p2) != shapes.end()); shape_info shape_info_p1 = shapes.find(p1)->second; shape_info shape_info_p2 = shapes.find(p2)->second; if (p1 == p2) { return "Draw!"; } else if (shape_info_p1.first & ~(shape_info_p2.second)) { return "Player 1 won!"; } else if (shape_info_p2.first & ~(shape_info_p1.second)) { return "Player 2 won!"; } else { assert(false); } }
string rps(const std::string p1, const std::string p2){std::map<std::string, int> dict;- std::string rps(const std::string p1, const std::string p2) {
- enum shape {
- rock = 1 << 0,
- paper = 1 << 1,
- scissors = 1 << 2,
- lizard = 1 << 3,
- spock = 1 << 4,
dict["rock"] = 0;dict["paper"] = 1;dict["scissors"] = 2;dict["lizard"] = 3;dict["spock"] = 4;- beaten_by_rock = shape::scissors | shape::lizard,
- beaten_by_paper = shape::spock | shape::rock,
- beaten_by_scissors = shape::paper | shape::lizard,
- beaten_by_lizard = shape::spock | shape::paper,
- beaten_by_spock = shape::scissors | shape::rock
- };
if(p1 == p2) return "Draw!";if(dict[p1] == 0){if(dict[p2] == 1) return "Player 2 won!";if(dict[p2] == 2) return "Player 1 won!";if(dict[p2] == 3) return "Player 1 won!";if(dict[p2] == 4) return "Player 2 won!";}if(dict[p1] == 1){if(dict[p2] == 0) return "Player 1 won!";if(dict[p2] == 2) return "Player 2 won!";if(dict[p2] == 3) return "Player 2 won!";if(dict[p2] == 4) return "Player 1 won!";}if(dict[p1] == 2){if(dict[p2] == 0) return "Player 2 won!";if(dict[p2] == 1) return "Player 1 won!";if(dict[p2] == 3) return "Player 1 won!";if(dict[p2] == 4) return "Player 2 won!";}if(dict[p1] == 3){if(dict[p2] == 0) return "Player 2 won!";if(dict[p2] == 1) return "Player 1 won!";if(dict[p2] == 2) return "Player 2 won!";if(dict[p2] == 4) return "Player 1 won!";}if(dict[p1] == 4){if(dict[p2] == 0) return "Player 1 won!";if(dict[p2] == 1) return "Player 2 won!";if(dict[p2] == 2) return "Player 1 won!";if(dict[p2] == 3) return "Player 2 won!";}- typedef std::pair<shape, shape> shape_info;
- static std::map<std::string, shape_info> shapes;
- if (shapes.empty()) {
- shapes.insert(std::make_pair("rock", std::make_pair(shape::rock, shape::beaten_by_rock)));
- shapes.insert(std::make_pair("paper", std::make_pair(shape::paper, shape::beaten_by_paper)));
- shapes.insert(std::make_pair("scissors", std::make_pair(shape::scissors, shape::beaten_by_scissors)));
- shapes.insert(std::make_pair("lizard", std::make_pair(shape::lizard, shape::beaten_by_lizard)));
- shapes.insert(std::make_pair("spock", std::make_pair(shape::spock, shape::beaten_by_spock)));
- }
- assert(shapes.find(p1) != shapes.end());
- assert(shapes.find(p2) != shapes.end());
- shape_info shape_info_p1 = shapes.find(p1)->second;
- shape_info shape_info_p2 = shapes.find(p2)->second;
- if (p1 == p2) {
- return "Draw!";
- } else if (shape_info_p1.first & ~(shape_info_p2.second)) {
- return "Player 1 won!";
- } else if (shape_info_p2.first & ~(shape_info_p1.second)) {
- return "Player 2 won!";
- } else {
- assert(false);
- }
- }
Describe(rock_paper_scissor_lizard_spock) { It(should_pass_some_example_tests) { Assert::That(rps("rock", "lizard"), Equals("Player 1 won!")); Assert::That(rps("paper", "rock"), Equals("Player 1 won!")); Assert::That(rps("rock", "paper"), Equals("Player 2 won!")); Assert::That(rps("lizard", "scissors"), Equals("Player 2 won!")); Assert::That(rps("spock", "spock"), Equals("Draw!")); } };
- Describe(rock_paper_scissor_lizard_spock)
- {
- It(should_pass_some_example_tests)
- {
- Assert::That(rps("rock", "lizard"), Equals("Player 1 won!"));
- Assert::That(rps("paper", "rock"), Equals("Player 1 won!"));
- Assert::That(rps("rock", "paper"), Equals("Player 2 won!"));
- Assert::That(rps("lizard", "scissors"), Equals("Player 2 won!"));
- Assert::That(rps("spock", "spock"), Equals("Draw!"));
- }
}- };
module Divisors where divisors :: Integer -> [Integer] divisors n = filter ((0 ==) . mod n) [1..n]
- module Divisors where
- divisors :: Integer -> [Integer]
divisors n = 1:n:(divisorsAux 2)wheredivisorsAux k| (fromIntegral k) > sqrt (fromIntegral n) = []| otherwise = if n `mod` k == 0then if n`div`k ==kthen k:(divisorsAux (k+1))else k:(n`div`k):(divisorsAux (k+1))else divisorsAux (k+1)- divisors n = filter ((0 ==) . mod n) [1..n]
def reverse_compliment(dna): DNA = dna.upper() rcom = [] for i in dna: if i == 'A': rcom.append('T') elif i == 'T': rcom.append('A') elif i == 'G': rcom.append('C') elif i == 'C': rcom.append('G') r = rcom[::-1] reversedna = ''.join(r) return reversedna
- def reverse_compliment(dna):
pass- DNA = dna.upper()
- rcom = []
- for i in dna:
- if i == 'A':
- rcom.append('T')
- elif i == 'T':
- rcom.append('A')
- elif i == 'G':
- rcom.append('C')
- elif i == 'C':
- rcom.append('G')
- r = rcom[::-1]
- reversedna = ''.join(r)
- return reversedna
package orderedcount // Use the preloaded Tuple struct as return type // type Tuple struct { // Char rune // Count int // } func OrderedCount(text string) []Tuple { tuples := make([]Tuple, 0) for _, c := range text { exists := false for _, t := range tuples { if(t.Char == rune(c)) { exists = true } } if (!exists) { tuples = append(tuples, Tuple{rune(c), 0}) } } for _, c := range text { for i := range tuples { if(tuples[i].Char == rune(c)) { tuples[i].Count++ } } } return tuples }
- package orderedcount
- // Use the preloaded Tuple struct as return type
- // type Tuple struct {
- // Char rune
- // Count int
- // }
- func OrderedCount(text string) []Tuple {
// to implement- tuples := make([]Tuple, 0)
- for _, c := range text {
- exists := false
- for _, t := range tuples {
- if(t.Char == rune(c)) {
- exists = true
- }
- }
- if (!exists) {
- tuples = append(tuples, Tuple{rune(c), 0})
- }
- }
- for _, c := range text {
- for i := range tuples {
- if(tuples[i].Char == rune(c)) {
- tuples[i].Count++
- }
- }
- }
- return tuples
- }
package orderedcount_test import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" . "codewarrior/orderedcount" ) var _ = Describe("Test Suite", func() { It("Sample Tests", func() { Expect(OrderedCount("abracadabra")).Should(Equal([]Tuple{Tuple{'a', 5}, Tuple{'b', 2}, Tuple{'r', 2}, Tuple{'c', 1}, Tuple{'d', 1}})) Expect(OrderedCount("Code Wars")).Should(Equal([]Tuple{Tuple{'C', 1}, Tuple{'o', 1}, Tuple{'d', 1}, Tuple{'e', 1}, Tuple{' ', 1}, Tuple{'W', 1}, Tuple{'a', 1}, Tuple{'r', 1}, Tuple{'s', 1}})) //Expect(OrderedCount("")).Should(Equal([]Tuple{})) }) })
- package orderedcount_test
- import (
- . "github.com/onsi/ginkgo"
- . "github.com/onsi/gomega"
- . "codewarrior/orderedcount"
- )
- var _ = Describe("Test Suite", func() {
- It("Sample Tests", func() {
- Expect(OrderedCount("abracadabra")).Should(Equal([]Tuple{Tuple{'a', 5}, Tuple{'b', 2}, Tuple{'r', 2}, Tuple{'c', 1}, Tuple{'d', 1}}))
- Expect(OrderedCount("Code Wars")).Should(Equal([]Tuple{Tuple{'C', 1}, Tuple{'o', 1}, Tuple{'d', 1}, Tuple{'e', 1}, Tuple{' ', 1}, Tuple{'W', 1}, Tuple{'a', 1}, Tuple{'r', 1}, Tuple{'s', 1}}))
Expect(OrderedCount("")).Should(Equal([]Tuple{}))- //Expect(OrderedCount("")).Should(Equal([]Tuple{}))
- })
- })
fn required_energy(heights: Vec<i64>) -> i64 { heights .iter() .skip(1) .zip(heights.iter()) .map(|(y2, y1)| (y2 - y1).abs()) .sum::<i64>() }
using System;public static class Kata{public static int CalculatingTheAmountEnergy(int[] coordinates){// here's your code}- fn required_energy(heights: Vec<i64>) -> i64 {
- heights
- .iter()
- .skip(1)
- .zip(heights.iter())
- .map(|(y2, y1)| (y2 - y1).abs())
- .sum::<i64>()
- }
#[test] fn test() { assert_eq!(required_energy(vec![1, 5, 10]), 9); assert_eq!(required_energy(vec![1, 5, 10, 3, 20]), 33); assert_eq!(required_energy(vec![0, 0, 1]), 1); }
using NUnit.Framework;using System;[TestFixture]public class SolutionTest{[TestCase(new int[] { 1, 5, 10}, ExpectedResult = 9)][TestCase(new int[] { 1, 5, 10, 3, 20}, ExpectedResult = 33)][TestCase(new int[] { 0, 0, 1}, ExpectedResult = 1)]public int Tests(int[] values) => Kata.CalculatingTheAmountEnergy(values);}- #[test]
- fn test() {
- assert_eq!(required_energy(vec![1, 5, 10]), 9);
- assert_eq!(required_energy(vec![1, 5, 10, 3, 20]), 33);
- assert_eq!(required_energy(vec![0, 0, 1]), 1);
- }