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

It looks like it it trying to walk-through the directories of a .venv virtual enviornment folder.

Code
Diff
  • import os
    
    # The subprocess module  is never used
    # import subprocess
    
    # Setting constant:
    DIR = os.path.join(os.getcwd(), 'venv')
    
    # Using the walrus operator to ve tp DIR, and printing results of venv directory:
    print((ve := os.listdir(DIR)))
    # For files in venv, which will be (Libs, and Scripts)
    for x in ve:
        try:
            # Printing a list of files, and directories within first directory of (venv)        
            print(x, os.listdir(os.path.join(DIR, x)))
            # FOr subfile in file:
            for y in x: 
                try:
                    # This does not get executed
                    print(x, os.listdir(os.path.join(DIR, x, y)))
                    # FOr super-sub file in subfile
                    for z in y:
                        try:
                            # This des not get executed
                            with open(os.path.join(DIR, x, y), 'r') as file:
                                print(file.read())
    
                        except:
                            # This does not get executed
                            print("...goes on...")
                except:
                    try:
                        # This does not get executed
                        with open(os.path.join(DIR, x), 'r') as file:
                            print(file.read())
                    except:
                        # This gets executed
                        print('')
        except:
            # This will get executed twice,  opening the .gitignore, and pyvenv.cfg file
            with open(os.path.join(DIR, x), 'r') as file:
                print(file.read())
    
    • import os
    • import subprocess
    • print((ve := os.listdir(".venv")))
    • # The subprocess module is never used
    • # import subprocess
    • # Setting constant:
    • DIR = os.path.join(os.getcwd(), 'venv')
    • # Using the walrus operator to ve tp DIR, and printing results of venv directory:
    • print((ve := os.listdir(DIR)))
    • # For files in venv, which will be (Libs, and Scripts)
    • for x in ve:
    • try:
    • print(x, os.listdir(f".venv/{x}"))
    • for y in x:
    • # Printing a list of files, and directories within first directory of (venv)
    • print(x, os.listdir(os.path.join(DIR, x)))
    • # FOr subfile in file:
    • for y in x:
    • try:
    • print(y, os.listdir(f".venv/{x}/{y}"))
    • # This does not get executed
    • print(x, os.listdir(os.path.join(DIR, x, y)))
    • # FOr super-sub file in subfile
    • for z in y:
    • try:
    • with open(f".venv/{x}/{y}/{z}","r") as file: print(file.open())
    • except:
    • # This des not get executed
    • with open(os.path.join(DIR, x, y), 'r') as file:
    • print(file.read())
    • except:
    • # This does not get executed
    • print("...goes on...")
    • except:
    • except:
    • try:
    • with open(rf".venv/{x}") as f:
    • print(f.read())
    • # This does not get executed
    • with open(os.path.join(DIR, x), 'r') as file:
    • print(file.read())
    • except:
    • print()
    • # This gets executed
    • print('')
    • except:
    • with open(rf".venv/{x}") as f:
    • print(f.read())
    • # This will get executed twice, opening the .gitignore, and pyvenv.cfg file
    • with open(os.path.join(DIR, x), 'r') as file:
    • print(file.read())
Code
Diff
  • feed_the_primates_v1 = lambda a,f: 'No bananas!' if "🍌" not in set(f) else ["🍌" for m in a if m in {"🐒", "🦍"} and "🍌" in f]
    
    banana = "🍌"
    feed_the_primates_v2 = lambda a,f: 'No bananas!' if banana not in set(f) else [banana for m in a if m in {"🐒", "🦍"} and banana in f]
    
    # other option being: replacing banana as inline value
    • def feed_the_primates_v1(animals, food):
    • return 'No bananas!' if "🍌" not in set(food) else ["🍌" for m in animals if m in {"🐒", "🦍"} and "🍌" in food]
    • feed_the_primates_v1 = lambda a,f: 'No bananas!' if "🍌" not in set(f) else ["🍌" for m in a if m in {"🐒", "🦍"} and "🍌" in f]
    • banana = "🍌"
    • feed_the_primates_v2 = lambda a,f: 'No bananas!' if banana not in set(f) else [banana for m in a if m in {"🐒", "🦍"} and banana in f]
    • def feed_the_primates_v2(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]
    • # other option being: replacing banana as inline value
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

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();
    • }
    • }