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.
Note that dist
is called twice per comparison, and there are length ps - 1
comparisons
{-# Language ViewPatterns #-} module ClosestPoint (closestPoint) where import Debug.Trace import Preloaded (Point,dist) import Data.List (minimumBy) -- extracts from a list of points the closest to a given point closestPoint :: Point -> [Point] -> Point closestPoint _ [] = undefined closestPoint point (traceShowId . trace "<hr>" -> ps) = minimumBy (\x y -> compare (dist point x) (dist point y)) ps
- {-# Language ViewPatterns #-}
- module ClosestPoint (closestPoint) where
- import Debug.Trace
- import Preloaded (Point,dist)
- import Data.List (minimumBy)
- -- extracts from a list of points the closest to a given point
- closestPoint :: Point -> [Point] -> Point
- closestPoint _ [] = undefined
closestPoint point ps = minimumBy (\x y -> compare (dist point x) (dist point y)) ps- closestPoint point (traceShowId . trace "<hr>" -> ps) = minimumBy (\x y -> compare (dist point x) (dist point y)) ps
module Closest (closestPoint) where type Point = (Float, Float) -- calculates the ditance between two points dist :: Point -> Point -> Float dist (x1, x2) (y1, y2) = sqrt (dx * dx + dy * dy) where (dx, dy) = (y1 - x1, y2 - x2) closestPoint :: Point -> [Point] -> Point closestPoint point [] = point closestPoint point (p : ps) = closest point (dist point p) p ps where closest :: Point -> Float -> Point -> [Point] -> Point closest p0 initialDist p1 [] = p1 closest p0 initialDist p1 (p2 : ps) | initialDist < dis = closest p0 initialDist p1 ps | otherwise = closest p0 dis p2 ps where dis = dist p0 p2
- module Closest (closestPoint) where
- type Point = (Float, Float)
- -- calculates the ditance between two points
- dist :: Point -> Point -> Float
- dist (x1, x2) (y1, y2)
- = sqrt (dx * dx + dy * dy)
- where (dx, dy) = (y1 - x1, y2 - x2)
- --- extracts from a list of points the closest to a given point
- closestPoint :: Point -> [Point] -> Point
closestPoint point [p] = pclosestPoint point (p : ps)= closest point p (closestPoint point ps)- closestPoint point [] = point
- closestPoint point (p : ps) = closest point (dist point p) p ps
- where
closest :: Point -> Point -> Point -> Pointclosest point p1 p2| dist point p1 < dist point p2 = p1| otherwise = p2- closest :: Point -> Float -> Point -> [Point] -> Point
- closest p0 initialDist p1 [] = p1
- closest p0 initialDist p1 (p2 : ps)
- | initialDist < dis = closest p0 initialDist p1 ps
- | otherwise = closest p0 dis p2 ps
- where
- dis = dist p0 p2
- Improve performance
- Refactor tests
- Refactor method signature
- Add documentation
using System.Linq; public static class Palindrome { public static bool IsPalindrome(this string word) { // Normalize the input var upper = word.ToUpperInvariant(); // For every chatacter in the first half.. for (var i = 0; i < upper.Length / 2; ++i) // if the char doesn't match the one in the second half.. if (upper[i] != upper[upper.Length - i - 1]) // the word is not a palindrome return false; // The word is not a palindrome return true; } }
- using System.Linq;
class Palindrome- public static class Palindrome
- {
public static bool Check(string word) {- public static bool IsPalindrome(this string word)
- {
- // Normalize the input
- var upper = word.ToUpperInvariant();
return upper.SequenceEqual(upper.Reverse());- // For every chatacter in the first half..
- for (var i = 0; i < upper.Length / 2; ++i)
- // if the char doesn't match the one in the second half..
- if (upper[i] != upper[upper.Length - i - 1])
- // the word is not a palindrome
- return false;
- // The word is not a palindrome
- return true;
- }
- }
namespace Solution { using NUnit.Framework; using System; // TODO: Replace examples and use TDD development by writing your own tests [TestFixture] public class SolutionTest { [TestCase(true, "MOM")] [TestCase(true, "kAyaK")] [TestCase(true, "123454321")] [TestCase(true, "n1oo1n")] [TestCase(true, "X")] [TestCase(true, "")] [TestCase(false, "rotlor")] [TestCase(false, "506050")] [TestCase(false, "idEddEddi")] public void AsExtension(bool expected, string toCheck) => Assert.AreEqual(expected, toCheck.IsPalindrome()); [TestCase(true, "MOM")] [TestCase(true, "kAyaK")] [TestCase(true, "123454321")] [TestCase(true, "n1oo1n")] [TestCase(true, "X")] [TestCase(true, "")] [TestCase(false, "rotlor")] [TestCase(false, "506050")] [TestCase(false, "idEddEddi")] public void AsMethod(bool expected, string toCheck) => Assert.AreEqual(expected, Palindrome.IsPalindrome(toCheck)); } }
- namespace Solution {
- using NUnit.Framework;
- using System;
- // TODO: Replace examples and use TDD development by writing your own tests
- [TestFixture]
- public class SolutionTest
- {
[Test]public void MyTest(){Assert.AreEqual(true, Palindrome.Check("MOM"));Assert.AreEqual(true, Palindrome.Check("kAyaK"));Assert.AreEqual(true, Palindrome.Check("123454321"));Assert.AreEqual(true, Palindrome.Check("n1oo1n"));Assert.AreEqual(true, Palindrome.Check("X"));Assert.AreEqual(true, Palindrome.Check(""));Assert.AreEqual(false, Palindrome.Check("rotlor"));Assert.AreEqual(false, Palindrome.Check("506050"));Assert.AreEqual(false, Palindrome.Check("idEddEddi"));}- [TestCase(true, "MOM")]
- [TestCase(true, "kAyaK")]
- [TestCase(true, "123454321")]
- [TestCase(true, "n1oo1n")]
- [TestCase(true, "X")]
- [TestCase(true, "")]
- [TestCase(false, "rotlor")]
- [TestCase(false, "506050")]
- [TestCase(false, "idEddEddi")]
- public void AsExtension(bool expected, string toCheck)
- => Assert.AreEqual(expected, toCheck.IsPalindrome());
- [TestCase(true, "MOM")]
- [TestCase(true, "kAyaK")]
- [TestCase(true, "123454321")]
- [TestCase(true, "n1oo1n")]
- [TestCase(true, "X")]
- [TestCase(true, "")]
- [TestCase(false, "rotlor")]
- [TestCase(false, "506050")]
- [TestCase(false, "idEddEddi")]
- public void AsMethod(bool expected, string toCheck)
- => Assert.AreEqual(expected, Palindrome.IsPalindrome(toCheck));
- }
- }
CAPITAL_LETTERS = ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z')
NUMBERS = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
SPACE = (' ')
def remove(ಠ‿ಠ):
for category in (CAPITAL_LETTERS, NUMBERS, SPACE):
for item in category:
while item in ಠ‿ಠ:
ಠ‿ಠ = remove(ಠ‿ಠ.replace(item, ''))
return ಠ‿ಠ
import string def remove(string): arr = list(string) test = "" for i in range (len(arr)): if arr[i].isupper() == True or arr[i] in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] or arr[i] == " ": arr[i] = "`" else: continue for i in arr: test += i return(test.replace("`", ""))
CAPITAL_LETTERS = ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M','N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z')NUMBERS = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')SPACE = (' ')- import string
- def remove(string):
- arr = list(string)
- test = ""
- for i in range (len(arr)):
- if arr[i].isupper() == True or arr[i] in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] or arr[i] == " ":
- arr[i] = "`"
- else:
- continue
- for i in arr:
- test += i
def remove(ಠ‿ಠ):for category in (CAPITAL_LETTERS, NUMBERS, SPACE):for item in category:while item in ಠ‿ಠ:ಠ‿ಠ = remove(ಠ‿ಠ.replace(item, ''))return ಠ‿ಠ- return(test.replace("`", ""))
var add1 = 0; var add2 = 0; var minus1 = 0; var minus2 = 0; var times1 = 0; var times2 = 0; var exponet1 = 0; var exponet2 = 0; var divide1 = 0; //Division with decimal var divide2 = 0; var divide3 = 0; //Division with remainder var divide4 = 0; var y = 15; console.log( add1 + add2 +" (Addition)"); var y = 35; console.log( minus1 - minus2 +" (Subtraction)" ); var y = 55; console.log( times1 * times2 +" (Multilplication)" ); var y = 75; console.log( divide1 / divide2 +" (Division with decimal)" ); var y = 95; console.log( Math.floor (divide3 / divide4) + " R" + divide3 % divide4 +" (Division with remainder)"); var y = 115; console.log( Math.pow(exponet2, exponet1) + " (Exponent) ");
// The operation with the number "1" goes firstvar add1 = 0var add2 = 0- var add1 = 0;
- var add2 = 0;
var minus1 = 0var minus2 = 0- var minus1 = 0;
- var minus2 = 0;
var divide1 = 0var divide2 = 0- var times1 = 0;
- var times2 = 0;
var times1 = 0var times2 = 0//change the numbers in the varibles above- var exponet1 = 0;
- var exponet2 = 0;
- var divide1 = 0; //Division with decimal
- var divide2 = 0;
- var divide3 = 0; //Division with remainder
- var divide4 = 0;
- var y = 15;
- console.log( add1 + add2 +" (Addition)");
- var y = 35;
- console.log( minus1 - minus2 +" (Subtraction)" );
- var y = 55;
- console.log( times1 * times2 +" (Multilplication)" );
- var y = 75;
- console.log( divide1 / divide2 +" (Division with decimal)" );
- var y = 95;
- console.log( Math.floor (divide3 / divide4) + " R" + divide3 % divide4 +" (Division with remainder)");
- var y = 115;
- console.log( Math.pow(exponet2, exponet1) + " (Exponent) ");
console.log("Addition" , add1 + add2) //Additionconsole.log("Subtraction", minus1-minus2) //Subtractionconsole.log("Division" , divide1/divide2) //Divisionconsole.log("Multiplication" , times1*times2) //Multiplication
//
- //
import codewars_test as test # TODO Write tests import solution # or from solution import example # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def tests(): @test.it("test split_strings") def test_split_strings(): test.assert_equals(split("aa"), ['a','a']) test.assert_equals(split("aabc12"), ['a','a','b','c','1','2'])
- import codewars_test as test
- # TODO Write tests
- import solution # or from solution import example
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
def test_group():@test.it("test case")def test_case():pass- def tests():
- @test.it("test split_strings")
- def test_split_strings():
- test.assert_equals(split("aa"), ['a','a'])
- test.assert_equals(split("aabc12"), ['a','a','b','c','1','2'])