Start a new Kumite
AllAgda (Beta)BF (Beta)CCFML (Beta)ClojureCOBOL (Beta)CoffeeScriptCommonLisp (Beta)CoqC++CrystalC#D (Beta)DartElixirElm (Beta)Erlang (Beta)Factor (Beta)Forth (Beta)Fortran (Beta)F#GoGroovyHaskellHaxe (Beta)Idris (Beta)JavaJavaScriptJulia (Beta)Kotlinλ Calculus (Beta)LeanLuaNASMNim (Beta)Objective-C (Beta)OCaml (Beta)Pascal (Beta)Perl (Beta)PHPPowerShell (Beta)Prolog (Beta)PureScript (Beta)PythonR (Beta)RacketRaku (Beta)Reason (Beta)RISC-V (Beta)RubyRustScalaShellSolidity (Beta)SQLSwiftTypeScriptVB (Beta)
Show only mine

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.

Ad
Ad
Code
Diff
  • 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 = dogs
    • first = True
    • while not checkEmpty(food):
    • for i in range(len(position)):
    • j = position[i]
    • if food[j] > 0:
    • food[j] -= 1
    • else:
    • move = moveDog(food, i, first, position)
    • if move != position[i]:
    • position[i] = move
    • food[move] -= 1
    • first = False
    • return position
    • 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 checkEmpty(food):
    • for i in food:
    • if i != 0: return False
    • return 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]
Strings
Fundamentals
Arrays

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).

Code
Diff
  • 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;
    • }
    • }