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.
def feedTheDogs(food,dogs,first=True): while any((i!=0 for i in food)): for i in range(len(dogs)): j=dogs[i] if food[j]>0:food[j]-=1 else: move=moveDog(food,i,first,dogs) if move!=dogs[i]:dogs[i]=move;food[move]-=1 first=False return dogs def closeDog(position,dog): closestDog=9999999999999;closest=9999999999999 for i in position: dif=abs(i-dog) if dif!=0 and dif<closest:closest=dif;closestDog=i elif dif!=0 and dif==closest:return dog return closestDog def moveDog(food,i,first,position): r=position[i];l=position[i] while r<len(food)-1 or l>0: if r<len(food)-1:r+=1 if l>0:l-=1 if food[r]>0 and food[l]==0:return r if food[r]==0 and food[l]>0:return l if food[r]>0 and food[l]>0: closestDog=closeDog(position,position[i]) if closestDog<position[i]:return r if closestDog>position[i]or closestDog==9999999999999:return l return position[i] return position[i]
def feedTheDogs(food, dogs):position = dogsfirst = Truewhile not checkEmpty(food):for i in range(len(position)):j = position[i]if food[j] > 0:food[j] -= 1else:move = moveDog(food, i, first, position)if move != position[i]:position[i] = movefood[move] -= 1first = Falsereturn positiondef closeDog(position, dog):closestDog = 9999999999999closest = 9999999999999for i in position:dif = abs(i - dog)if dif != 0 and dif < closest:closest = difclosestDog = ielif dif != 0 and dif == closest:return dogreturn closestDogdef moveDog(food, i, first, position):r = position[i]l = position[i]while r < len(food) - 1 or l > 0:if r < len(food) - 1: r += 1if l > 0: l -= 1if food[r] > 0 and food[l] == 0: return rif food[r] == 0 and food[l] > 0: return lif food[r] > 0 and food[l] > 0:closestDog = closeDog(position, position[i])if closestDog < position[i]: return rif closestDog > position[i] or closestDog == 9999999999999: return lreturn position[i]return position[i]def checkEmpty(food):for i in food:if i != 0: return Falsereturn True- def feedTheDogs(food,dogs,first=True):
- while any((i!=0 for i in food)):
- for i in range(len(dogs)):
- j=dogs[i]
- if food[j]>0:food[j]-=1
- else:
- move=moveDog(food,i,first,dogs)
- if move!=dogs[i]:dogs[i]=move;food[move]-=1
- first=False
- return dogs
- def closeDog(position,dog):
- closestDog=9999999999999;closest=9999999999999
- for i in position:
- dif=abs(i-dog)
- if dif!=0 and dif<closest:closest=dif;closestDog=i
- elif dif!=0 and dif==closest:return dog
- return closestDog
- def moveDog(food,i,first,position):
- r=position[i];l=position[i]
- while r<len(food)-1 or l>0:
- if r<len(food)-1:r+=1
- if l>0:l-=1
- if food[r]>0 and food[l]==0:return r
- if food[r]==0 and food[l]>0:return l
- if food[r]>0 and food[l]>0:
- closestDog=closeDog(position,position[i])
- if closestDog<position[i]:return r
- if closestDog>position[i]or closestDog==9999999999999:return l
- return position[i]
- return position[i]
import codewars_test as test 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(): test.assert_equals(feedTheDogs([1,2,3,6],[0,3]),[2,3]) test.assert_equals(feedTheDogs([1,1,1,6,2,1],[1,3]),[4,5]) test.assert_equals(feedTheDogs([1,6,1,],[0,2]),[1,1]) test.assert_equals(feedTheDogs([1,0,1,0,1],[0,4]),[2,4]) test.assert_equals(feedTheDogs([1,0,0,0,1],[2,4]),[0,4]) test.assert_equals(feedTheDogs([4,0,3,1,0],[1,4]),[0,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():
- test.assert_equals(feedTheDogs([1,2,3,6],[0,3]),[2,3])
- test.assert_equals(feedTheDogs([1,1,1,6,2,1],[1,3]),[4,5])
- test.assert_equals(feedTheDogs([1,6,1,],[0,2]),[1,1])
- test.assert_equals(feedTheDogs([1,0,1,0,1],[0,4]),[2,4])
- test.assert_equals(feedTheDogs([1,0,0,0,1],[2,4]),[0,4])
- test.assert_equals(feedTheDogs([4,0,3,1,0],[1,4]),[0,2])
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; // TODO: Replace examples and use TDD by writing your own tests class SolutionTest { @Test void testSomething() { // assertEquals("expected", "actual"); } @Test void isEmpty(){ assertEquals("",phoneWords.phoneWords("")); } @Test void BasicTest(){ assertEquals("hello how are you", phoneWords.phoneWords("443355555566604466690277733099966688")); assertEquals("kata", phoneWords.phoneWords("55282")); assertEquals("im a tester", phoneWords.phoneWords("44460208337777833777")); assertEquals("codewars", phoneWords.phoneWords("22266631339277717777")); assertEquals("null", phoneWords.phoneWords("66885551555")); assertEquals("text", phoneWords.phoneWords("833998")); assertEquals("", phoneWords.phoneWords("0000000")); assertEquals("java", phoneWords.phoneWords("528882")); assertEquals("kumite", phoneWords.phoneWords("55886444833")); assertEquals("apple",phoneWords.phoneWords("271755533")); assertEquals("" , phoneWords.phoneWords("")); } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- // TODO: Replace examples and use TDD by writing your own tests
- class SolutionTest {
- @Test
- void testSomething() {
- // assertEquals("expected", "actual");
- }
- @Test
- void isEmpty(){
- assertEquals("",phoneWords.phoneWords(""));
- }
- @Test
- void BasicTest(){
assertEquals("hello how are you",phoneWords.phoneWords("443355555566604466690277733099966688"));assertEquals("kata",phoneWords.phoneWords("55282"));- assertEquals("hello how are you", phoneWords.phoneWords("443355555566604466690277733099966688"));
- assertEquals("kata", phoneWords.phoneWords("55282"));
- assertEquals("im a tester", phoneWords.phoneWords("44460208337777833777"));
- assertEquals("codewars", phoneWords.phoneWords("22266631339277717777"));
- assertEquals("null", phoneWords.phoneWords("66885551555"));
- assertEquals("text", phoneWords.phoneWords("833998"));
- assertEquals("", phoneWords.phoneWords("0000000"));
- assertEquals("java", phoneWords.phoneWords("528882"));
- assertEquals("kumite", phoneWords.phoneWords("55886444833"));
- assertEquals("apple",phoneWords.phoneWords("271755533"));
- assertEquals("" , phoneWords.phoneWords(""));
- }
- }
The police have placed radars that will detect those vehicles that exceed the speed limit on that road. If the driver's speed is 10km/h to 19km/h above the speed limit, the fine will be 100 euros, if it is exceeded by 20km/h to 29km/h the fine will be 250 euros and if it is exceeded by more than 30km/h the fine will be 500 euros.
You will be provided with the speed limits of those roads with radar as an array of integers (int speeds [90,100,110,120,....]) and the speed of the driver will be the same on all roads and the amount of the fine will be accumulated (example 95km/h).
public class Kata { public static int speedLimit(int speed, int[] signals) { int penalty = 0; for (int i = 0; i < signals.length; i++){ if (speed > signals[i]){ if (speed - signals[i] >= 30){ penalty += 500; } else if (speed - signals[i] >= 20 && speed - signals[i] < 30){ penalty += 250; } else if (speed - signals[i] >= 10 && speed - signals[i] < 20){ penalty += 100; } } } return penalty; } }
- public class Kata {
- public static int speedLimit(int speed, int[] signals) {
- int penalty = 0;
- for (int i = 0; i < signals.length; i++){
- if (speed > signals[i]){
- if (speed - signals[i] >= 30){
- penalty += 500;
- } else if (speed - signals[i] >= 20 && speed - signals[i] < 30){
- penalty += 250;
- } else if (speed - signals[i] >= 10 && speed - signals[i] < 20){
- penalty += 100;
- }
- }
- }
- return penalty;
- }
- }