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.
class Sort: def merge_sort(self, nums): if nums == None: return None elif len(nums) <= 1: return nums vLeft = self.merge_sort(nums[:len(nums) // 2]) vRight= self.merge_sort(nums[len(nums) // 2:]) lLeft,lRight = len(vLeft),len(vRight) i,j,k = 0,0,0 while i < lLeft and j < lRight: if vLeft[i] < vRight[j]: nums[k] = vLeft[i] i += 1 else: nums[k] = vRight[j] j += 1 k += 1 while i < lLeft: nums[k] = vLeft[i] i += 1 k += 1 while j < lRight: nums[k] = vRight[j] j += 1 k += 1 return nums
- class Sort:
- def merge_sort(self, nums):
- if nums == None: return None
if len(nums) > 1:mid = len(nums) // 2lefthalf = nums[:mid]righthalf = nums[mid:]self.merge_sort(lefthalf)self.merge_sort(righthalf)i = 0j = 0k = 0while i < len(lefthalf) and j < len(righthalf):if lefthalf[i] < righthalf[j]:nums[k] = lefthalf[i]i += 1else:nums[k] = righthalf[j]j += 1k += 1while i < len(lefthalf):nums[k] = lefthalf[i]- elif len(nums) <= 1: return nums
- vLeft = self.merge_sort(nums[:len(nums) // 2])
- vRight= self.merge_sort(nums[len(nums) // 2:])
- lLeft,lRight = len(vLeft),len(vRight)
- i,j,k = 0,0,0
- while i < lLeft and j < lRight:
- if vLeft[i] < vRight[j]:
- nums[k] = vLeft[i]
- i += 1
k += 1while j < len(righthalf):nums[k] = righthalf[j]- else:
- nums[k] = vRight[j]
- j += 1
k += 1- k += 1
- while i < lLeft:
- nums[k] = vLeft[i]
- i += 1
- k += 1
- while j < lRight:
- nums[k] = vRight[j]
- j += 1
- k += 1
- return nums
Changed from a static variable to a dynamic function.
module Solution export greet function greet( whom::String ) "Hello " * whom * "!" end end
println("Hello Julia!")const hello = "world"- module Solution
- export greet
- function greet( whom::String )
- "Hello " * whom * "!"
- end
- end
using FactCheck facts("greetings") do @fact Solution.greet("world") --> "Hello world!" @fact Solution.greet("Julia") --> "Hello Julia!" @fact Solution.greet("Fred") --> "Hello Fred!" @fact Solution.greet("Kmactavish") --> "Hello Kmactavish!" end
facts("Is hello world?") do@fact hello => "world"- using FactCheck
- facts("greetings") do
- @fact Solution.greet("world") --> "Hello world!"
- @fact Solution.greet("Julia") --> "Hello Julia!"
- @fact Solution.greet("Fred") --> "Hello Fred!"
- @fact Solution.greet("Kmactavish") --> "Hello Kmactavish!"
- end
def add(string, option): odd,even = 0,0 for x in string: x = int(x) if x%2 ==0:even+=x if x%2 ==1:odd+=x if option ==0: return odd+even return even if option == 2 else odd
- def add(string, option):
even_list = []odd_list = []all_sum = 0for num in string:num = int(num)all_sum += numif num % 2 == 0:even_list.append(num)if num % 2 != 0:odd_list.append(num)if option == 0:return all_sumif option == 1:return sum(odd_list)if option == 2:return sum(even_list)- odd,even = 0,0
- for x in string:
- x = int(x)
- if x%2 ==0:even+=x
- if x%2 ==1:odd+=x
- if option ==0:
- return odd+even
- return even if option == 2 else odd
test.assert_equals(add("1234567", 0),28) test.assert_equals(add("1234567", 1),16) test.assert_equals(add("1234567", 2),12)
test.assert_equals(add("1234567" , 0),28)test.assert_equals(add("1234567" , 1),16)test.assert_equals(add("1234567" , 2),12)- test.assert_equals(add("1234567", 0),28)
- test.assert_equals(add("1234567", 1),16)
- test.assert_equals(add("1234567", 2),12)
def distance(a): y,y1 = 0,0 for i in range(len(a)): if "y" in a[i]: y = i if "x" in a[i]: y1 = i x ,x1 = a[y].index("y"), a[y1].index("x") return abs(x -x1) + abs(y-y1)
def distance(array):for i in range(len(array)):if "y" in array[i] : y = abs(array[i].index("y") - i)if "x" in array[i] : x = abs(array[i].index("x") - i)return (x+y)- def distance(a):
- y,y1 = 0,0
- for i in range(len(a)):
- if "y" in a[i]: y = i
- if "x" in a[i]: y1 = i
- x ,x1 = a[y].index("y"), a[y1].index("x")
- return abs(x -x1) + abs(y-y1)
def fizz_buzz(n): return ['FizzBuzz' if (i % 15 == 0) else 'Fizz' if(i % 3 == 0) else 'Buzz' if(i % 5 == 0) else i for i in range(1,n)]
- def fizz_buzz(n):
for i in range(1, n):yield "Fizz" * (i % 3 == 0) + "Buzz" * (i % 5 == 0) or i- return ['FizzBuzz' if (i % 15 == 0) else 'Fizz' if(i % 3 == 0) else 'Buzz' if(i % 5 == 0) else i for i in range(1,n)]
A different approach from the one above, done in one line.
const minutes = i => `${Math.trunc(i / 60)}:${i % 60 < 10 ? "0" : ""}${i % 60}`;
const toHours = i => Math.floor(i / 60);const setDigits = i => `0${i}`.slice(-2);const getTime = i => [toHours(i), i % 60];const toTime = arr => `${arr[0]}:${setDigits(arr[1])}`;const minutes = i => toTime(getTime(i));- const minutes = i => `${Math.trunc(i / 60)}:${i % 60 < 10 ? "0" : ""}${i % 60}`;
Using Math.max
public class BiggerNum{ /** * @param a integer of param1 * @param b integer of param2 * @return the bigger integer of a and b * If a equals b, return either one */ public static int compare(int a, int b) { return Math.max(a,b); } }
- public class BiggerNum{
- /**
- * @param a integer of param1
- * @param b integer of param2
- * @return the bigger integer of a and b
* If a equals b, eiter one is acceptance- * If a equals b, return either one
- */
- public static int compare(int a, int b) {
return a >= b ? a : b;- return Math.max(a,b);
- }
- }
import org.junit.Test; import static org.junit.Assert.assertEquals; import org.junit.runners.JUnit4; public class SolutionTest { @Test public void should_return_a_when_a_gt_b() { int a = 10; int b = 5; assertEquals(a, BiggerNum.compare(a, b)); } @Test public void should_return_b_when_a_lt_b() { int a = 4; int b = 5; assertEquals(b, BiggerNum.compare(a, b)); } @Test public void should_return_either_when_a_eq_b() { int a = 5; int b = 5; assertEquals(5, BiggerNum.compare(a, b)); } }
- import org.junit.Test;
- import static org.junit.Assert.assertEquals;
- import org.junit.runners.JUnit4;
// TODO: Replace examples and use TDD development by writing your own tests- public class SolutionTest {
- @Test
- public void should_return_a_when_a_gt_b() {
- int a = 10;
- int b = 5;
- assertEquals(a, BiggerNum.compare(a, b));
- }
- @Test
- public void should_return_b_when_a_lt_b() {
- int a = 4;
- int b = 5;
- assertEquals(b, BiggerNum.compare(a, b));
- }
- @Test
- public void should_return_either_when_a_eq_b() {
- int a = 5;
int b = 5;- int b = 5;
- assertEquals(5, BiggerNum.compare(a, b));
- }
- }
Using OP's description:
- Premium: UltraHD and 4 devices
- Standard: HD and 2 devices
- Essential: 1 device
Fixed checks and added invalid case for a list of parameters that does not work. Changed the two bool parameters to an enum, since you probably won't be purchasing both HD and UHD simultaneously.
using System; public enum Quality { SD, HD, UHD } public class TV { public static string GetContract( int numDevices, Quality quality) { string result = "INVALID"; if (numDevices == 4 && quality == Quality.UHD) result = "PREMIUM"; else if (numDevices == 2 && quality == Quality.HD) result = "STANDARD"; else if (numDevices == 1 && quality == Quality.SD) result = "ESSENTIAL"; return result; } }
- using System;
public class Kata{public static string GetContract( int numberOfDevices, bool ultraHd, bool hd){string result = "ESSENTIEL";if (numberOfDevices>2 || ultraHd){result = "PREMIUM";}else{if (numberOfDevices == 2 || hd){result = "STANDARD";}}return result;- public enum Quality { SD, HD, UHD }
}- public class TV
- {
- public static string GetContract( int numDevices, Quality quality)
- {
- string result = "INVALID";
- if (numDevices == 4 && quality == Quality.UHD)
- result = "PREMIUM";
- else if (numDevices == 2 && quality == Quality.HD)
- result = "STANDARD";
- else if (numDevices == 1 && quality == Quality.SD)
- result = "ESSENTIAL";
- return result;
- }
- }
namespace Solution { using NUnit.Framework; using System; [TestFixture] public class SolutionTest { [Test] public void TestMethodGetContract4() { var actual = TV.GetContract(4, Quality.SD); var expected = "INVALID"; Assert.AreEqual(expected, actual); } [Test] public void TestMethodGetContract2() { var actual = TV.GetContract(2, Quality.SD); var expected = "INVALID"; Assert.AreEqual(expected, actual); } [Test] public void TestMethodGetContractSD() { var actual = TV.GetContract(1, Quality.SD); var expected = "ESSENTIAL"; Assert.AreEqual(expected, actual); } [Test] public void TestMethodGetContractUltraHD() { var actual = TV.GetContract(4, Quality.UHD); var expected = "PREMIUM"; Assert.AreEqual(expected, actual); } [Test] public void TestMethodGetContractHD() { var actual = TV.GetContract(2, Quality.HD); var expected = "STANDARD"; Assert.AreEqual(expected, actual); } } }
- 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 TestMethodGetContract4(){var actual = Kata.GetContract(4, false, false);var expected = "PREMIUM";Assert.AreEqual(expected, actual);}[Test]public void TestMethodGetContract2(){var actual = Kata.GetContract(2, false, false);var expected = "STANDARD";Assert.AreEqual(expected, actual);}[Test]public void TestMethodGetContract1(){var actual = Kata.GetContract(1, false, false);var expected = "ESSENTIEL";Assert.AreEqual(expected, actual);}[Test]public void TestMethodGetContractUltraHD(){var actual = Kata.GetContract(1, true, false);var expected = "PREMIUM";Assert.AreEqual(expected, actual);}[Test]public void TestMethodGetContractHD(){var actual = Kata.GetContract(1, false, true);var expected = "STANDARD";Assert.AreEqual(expected, actual);}- [Test]
- public void TestMethodGetContract4()
- {
- var actual = TV.GetContract(4, Quality.SD);
- var expected = "INVALID";
- Assert.AreEqual(expected, actual);
- }
- [Test]
- public void TestMethodGetContract2()
- {
- var actual = TV.GetContract(2, Quality.SD);
- var expected = "INVALID";
- Assert.AreEqual(expected, actual);
- }
- [Test]
- public void TestMethodGetContractSD()
- {
- var actual = TV.GetContract(1, Quality.SD);
- var expected = "ESSENTIAL";
- Assert.AreEqual(expected, actual);
- }
- [Test]
- public void TestMethodGetContractUltraHD()
- {
- var actual = TV.GetContract(4, Quality.UHD);
- var expected = "PREMIUM";
- Assert.AreEqual(expected, actual);
- }
- [Test]
- public void TestMethodGetContractHD()
- {
- var actual = TV.GetContract(2, Quality.HD);
- var expected = "STANDARD";
- Assert.AreEqual(expected, actual);
- }
- }
- }