Begin a new Kumite
Search
About
  • Filter by Language:
  • 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.

Code
Diff
  • public class Kata {
        public static int findShort(String s) {
            int shortest = Integer.MAX_VALUE;
            for(String word : s.split(" ")) {
                int current = word.length();
                shortest = current < shortest ? current : shortest;
            }
            return shortest;
        }
    }
  • 1-import java.util.stream.*;
    22 public class Kata {
    33 public static int findShort(String s) {
    4- return Stream.of(s.split(" "))
    5- .mapToInt(String::length)
    6- .min()
    7- .getAsInt();
    3+ int shortest = Integer.MAX_VALUE;
    4+ for(String word : s.split(" ")) {
    5+ int current = word.length();
    6+ shortest = current < shortest ? current : shortest;
    7+ }
    8+ return shortest;
    88 }
    99 }

A better choice for your use-case would be an enum. First of all it is reusable, second, if you need to store it in a variable, a check will later read if rating == Rating.Okay, not if rating == 3, so no magic constants.

Code
Diff
  • from enum import Enum
    
    class Rating(Enum):
      Terrible = 1
      Bad = 2
      Okay = 3
      Good = 4
      Excellent = 5
      
    def rating(i: int) -> str:
      try:
        return Rating(i).name
      except ValueError:
        return "Please enter a value between 1-5"
  • 1-def rating(r):
    2- if r is 5:
    3- return 'Excellent'
    4- elif r is 4:
    5- return 'Good'
    6- elif r is 3:
    7- return 'Okay'
    8- elif r is 2:
    9- return 'Bad'
    10- elif r is 1:
    11- return 'Terrible'
    12- else:
    13- return 'Enter a rating from 1 to 5'
    1+from enum import Enum
    2+
    3+class Rating(Enum):
    4+ Terrible = 1
    5+ Bad = 2
    6+ Okay = 3
    7+ Good = 4
    8+ Excellent = 5
    9+
    10+def rating(i: int) -> str:
    11+ try:
    12+ return Rating(i).name
    13+ except ValueError:
    14+ return "Please enter a value between 1-5"
Code
Diff
  • public class Kata {
      public static String solution(String text) {
    
        return new StringBuilder(text).reverse().toString();
    
      }
    }
  • 11 public class Kata {
    2+ public static String solution(String text) {
    22
    3- public static String solution(String str) {
    4- // Your code here...
    5- StringBuilder res = new StringBuilder(str.length());
    6-
    7- for (int i = (str.length() - 1); i >= 0; i--){
    8- res.append(str.charAt(i));
    9- }
    10-
    11- return res.toString();
    12- }
    4+ return new StringBuilder(text).reverse().toString();
    1313
    6+ }
    1414 }
public class Kata
    {
        public static int opposite(int number)
        {
        return -number;
        }
    }
Code
Diff
  • bool isLeap(int year) {
      return (year&3) == 0 && (year % 100 != 0 || (year&15) == 0);
    }
  • 11 bool isLeap(int year) {
    2- if(year % 4 != 0 || (year % 100 == 0 && year % 400 != 0)) return false;
    3- return true;
    2+ return (year&3) == 0 && (year % 100 != 0 || (year&15) == 0);
    44 }
ES2015
Babel
Code
Diff
  • pi=el=>3.13
  • 1-pi=_=>3.13
    1+pi=el=>3.13