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
Code
Diff
  • print("Hello", "word") #p fix the cde dumbfuck
    • print("Hello word") #p fix the cde dumbfuck
    • print("Hello", "word") #p fix the cde dumbfuck
Code
Diff
  • def feed_the_primates_v1(animals, food):
        banana = "🍌"
        return 'No bananas!' if banana not in set(food) else [banana for m in animals if m in {"🐒", "🦍"} and banana in food]
    
    
    def feed_the_primates_v2(animals: list, food: list) -> any:
        return 'No bananas!' if "🍌" not in food else list(
            map(lambda a: f"🍌{a}", filter(lambda m: m if m in ["🐒", "🦍"] else None, animals)))
    
    
    • def feed_the_primates_v1(animals, food):
    • food = set(food)
    • banana = "🍌"
    • if banana not in food:
    • return 'No bananas!'
    • return [banana for m in animals if m in {"🐒", "🦍"} and banana in food]
    • return 'No bananas!' if banana not in set(food) else [banana for m in animals if m in {"🐒", "🦍"} and banana in food]
    • def feed_the_primates_v2(animals: list, food: list) -> any:
    • return 'No bananas!' if "🍌" not in food else list(
    • map(lambda a: f"🍌{a}", filter(lambda m: m if m in ["🐒", "🦍"] else None, animals)))

you can do this weird import thing to achive the one-line.

Code
Diff
  • def quine():return __import__("inspect").getsource(quine)
    • def quine(): from inspect import getsource ; return getsource(quine)
    • def quine():return __import__("inspect").getsource(quine)
Strings
Code
Diff
  • public class ColorAdder
    {
        public static string AddColor(string color, string text)
        {
          string Reset = "\033[0m";
          
          return color switch{
              "Red" => $"\033[31m{text}{Reset}",
              "Green" => $"\033[32m{text}{Reset}",
              "Yellow" => $"\033[33m{text}{Reset}",
              "Blue" => $"\033[34m{text}{Reset}",
              "Magenta" => $"\033[35m{text}{Reset}",
              "Cyan" => $"\033[36m{text}{Reset}",
              "White" => $"\033[37m{text}{Reset}",
              _ => ""
          };
        }
    }
    
    • public class ColorAdder
    • {
    • public static string AddColor(string color, string text)
    • {
    • string Reset = "\033[0m";
    • string Red = "\033[31m";
    • string Green = "\033[32m";
    • string Yellow = "\033[33m";
    • string Blue = "\033[34m";
    • string Magenta = "\033[35m";
    • string Cyan = "\033[36m";
    • string White = "\033[37m";
    • switch(color) {
    • case "Red":
    • return string.Concat(string.Concat(Red, text), Reset);
    • break;
    • case "Green":
    • return string.Concat(string.Concat(Green, text), Reset);
    • break;
    • case "Yellow":
    • return string.Concat(string.Concat(Yellow, text), Reset);
    • break;
    • case "Blue":
    • return string.Concat(string.Concat(Blue, text), Reset);
    • break;
    • case "Magenta":
    • return string.Concat(string.Concat(Magenta, text), Reset);
    • break;
    • case "Cyan":
    • return string.Concat(string.Concat(Cyan, text), Reset);
    • break;
    • case "White":
    • return string.Concat(string.Concat(White, text), Reset);
    • break;
    • default:
    • return "Invalid Color";
    • break;
    • }
    • return color switch{
    • "Red" => $"\033[31m{text}{Reset}",
    • "Green" => $"\033[32m{text}{Reset}",
    • "Yellow" => $"\033[33m{text}{Reset}",
    • "Blue" => $"\033[34m{text}{Reset}",
    • "Magenta" => $"\033[35m{text}{Reset}",
    • "Cyan" => $"\033[36m{text}{Reset}",
    • "White" => $"\033[37m{text}{Reset}",
    • _ => ""
    • };
    • }
    • }
Code
Diff
  • import static java.time.format.DateTimeFormatter.ofPattern;
    
    import java.time.LocalDateTime;
    
    public class Account {
      private Transaction current = new Transaction(0, 0);
    
      public void deposit(int amount) {
        current = new Transaction(current.balance() + amount, Math.abs(amount));
      }
    
      public void withdraw(int amount) {
        deposit(-amount);
      }
    
      public String printStatement() {
        return current.toString();
      }
    
      private record Transaction(int balance, int amount, LocalDateTime date) {
    
        public Transaction(int balance, int amount) {
          this(balance, amount, LocalDateTime.now());
        }
    
        @Override
        public String toString() {
          return String.format("Date Amount Balance%n%s%n%s %d %d",
              balance < 0 ? "Failed: Insufficient Funds" : amount <= 0 ? "Failed: Negative Transaction" : "",
              date.format(ofPattern("dd-MM-yyyy")), amount, balance);
        }
      }
    }
    • import static java.time.format.DateTimeFormatter.ofPattern;
    • import java.time.LocalDateTime;
    • import java.time.format.DateTimeFormatter;
    • public class Account {
    • private Transaction current = new Transaction(0, 0);
    • public void deposit(int amount) {
    • current = new Transaction(current.balance() + amount, Math.abs(amount));
    • }
    • LocalDateTime lastTransactionDate = LocalDateTime.of(1900,1,1,1,1);
    • int lastTransactionAmount = 0;
    • int lastTransactionBalance = 0;
    • private String statement = "Date Amount Balance" + "\n";
    • private static final String DATE_FORMATTER= "dd-MM-yyyy";
    • DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_FORMATTER);
    • public void withdraw(int amount) {
    • deposit(-amount);
    • }
    • public String printStatement() {
    • return current.toString();
    • }
    • private record Transaction(int balance, int amount, LocalDateTime date) {
    • public String printStatement() {
    • if(this.lastTransactionBalance < 0){
    • return this.statement + "\n Failed: Insufficient Funds";
    • } else if(this.lastTransactionAmount <= 0){
    • return this.statement + "Failed: Negative Transaction";
    • }
    • return this.statement + "\n" + lastTransactionDate.format(formatter) + " " + lastTransactionAmount + " " + lastTransactionBalance;
    • public Transaction(int balance, int amount) {
    • this(balance, amount, LocalDateTime.now());
    • }
    • public void deposit(int amount){
    • this.lastTransactionBalance += amount;
    • this.lastTransactionAmount = amount;
    • this.lastTransactionDate = LocalDateTime.now();;
    • @Override
    • public String toString() {
    • return String.format("Date Amount Balance%n%s%n%s %d %d",
    • balance < 0 ? "Failed: Insufficient Funds" : amount <= 0 ? "Failed: Negative Transaction" : "",
    • date.format(ofPattern("dd-MM-yyyy")), amount, balance);
    • }
    • public void withdraw(int amount){
    • this.lastTransactionBalance -= amount;
    • this.lastTransactionAmount = amount;
    • this.lastTransactionDate = LocalDateTime.now();
    • }
    • }
Strings
Fundamentals
Code
Diff
  • interface PhoneWords {
      static String phoneWords(String str) {
        String[] pad = {" ", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
        var message = new StringBuilder();
        for (int i = 0, j; i < str.length(); i += j + 1) {
          var abc = pad[str.charAt(i) - 48];
          j = offset(str, abc.length() - 1, i);
          message.append(abc.charAt(j));
        }
        return message.toString();
      }
    
      private static int offset(String str, int length, int i) {
        int j = 0;
        while (j < length && i + j < str.length() - 1 && str.charAt(i + j) == str.charAt(i + j + 1)) {
          j++;
        }
        return j;
      }
    }
    • import java.util.Map;
    • import java.util.HashMap;
    • interface PhoneWords {
    • static String phoneWords(String str) {
    • String[] pad = {" ", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
    • var message = new StringBuilder();
    • for (int i = 0, j; i < str.length(); i += j + 1) {
    • var abc = pad[str.charAt(i) - 48];
    • j = offset(str, abc.length() - 1, i);
    • message.append(abc.charAt(j));
    • }
    • return message.toString();
    • }
    • public class phoneWords{
    • final static Map<Character, String> map = new HashMap<Character, String>() {{
    • put('0', " ");
    • put('2', "abc");
    • put('3', "def");
    • put('4', "ghi");
    • put('5', "jkl");
    • put('6', "mno");
    • put('7', "pqrs");
    • put('8', "tuv");
    • put('9', "wxyz");
    • }};
    • public static String phoneWords(String str){
    • StringBuilder mensaje = new StringBuilder();
    • for (int i = 0; i < str.length(); ++i) {
    • char letter = str.charAt(i);
    • int cont = 0;
    • int comparator = "79".indexOf(letter) == -1? 2: 3;
    • while (cont != comparator && i != str.length() - 1 && str.charAt(i) == str.charAt(i + 1)) {
    • ++cont;
    • ++i;
    • }
    • mensaje.append(map.get(letter).charAt(cont));
    • }
    • return mensaje.toString();
    • }
    • private static int offset(String str, int length, int i) {
    • int j = 0;
    • while (j < length && i + j < str.length() - 1 && str.charAt(i + j) == str.charAt(i + j + 1)) {
    • j++;
    • }
    • return j;
    • }
    • }
Code
Diff
  • ring = ''.join([chr(i+7) for i in [90, 90, 90, 90, 90, 110, 110, 110, 96, 96, 97, 97, 97, 97]])
    • x = '\a'
    • ring = ''.join([chr(i+7) for i in [90, 90, 90, 90, 90, 110, 110, 110, 96, 96, 97, 97, 97, 97]])