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
  • print([i for i in range(0, 51, 2) if i % 3 != 0])                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          ("hello")
    • print ("hello")
    • print([i for i in range(0, 51, 2) if i % 3 != 0]) ("hello")
Code
Diff
  • RandomBool=lambda:bool(ord('}')>ord(open('/dev/urandom','rb').read(True^False)))^\
    __import__("secrets").choice([__import__("random").getrandbits(1),
                                  __import__("random").getrandbits(1)])
    # might as well make it worse...
    • RandomBool=lambda:bool(ord(open('/dev/urandom','rb').read(1))&1)
    • # This is also terribad, and the previous randint ones are better, but why not keep having fun
    • RandomBool=lambda:bool(ord('}')>ord(open('/dev/urandom','rb').read(True^False)))^\
    • __import__("secrets").choice([__import__("random").getrandbits(1),
    • __import__("random").getrandbits(1)])
    • # might as well make it worse...
Code
Diff
  • def poopFarter(p):
        return "πŸ’©" if p else "πŸ’¨"
        
    • def poopFarter(boolean):
    • if boolean == True:
    • return("pooper")
    • else:
    • return("farter")
    • def poopFarter(p):
    • return "πŸ’©" if p else "πŸ’¨"
Object-oriented Programming
Games
Code
Diff
  • from dataclasses import dataclass
    import time
    import random
    
    
    @dataclass
    class Gladiator:
        name: str
        hp: int
        damage: int
        speed: int
        is_alive: bool = True
    
    
    # Define the fight function
    def fight(player_1: Gladiator, player_2: Gladiator) -> None:
        """This function handles teh main fight sequences"""
        winner = None
    
        # Determine first attacker based on speed
        gladiatorAlpha = max(player_1, player_2, key=lambda i: i.speed)
        gladiatorBravo = min(player_1, player_2, key=lambda i: i.speed)
    
        # Print Player vs Player
        print(f"{gladiatorAlpha.name.title()} vs {gladiatorBravo.name}")
        time.sleep(1)
        print('--- FIGHT! ---\n'.center(20))
        time.sleep(1)
    
        # Main game loop:
        while gladiatorAlpha.is_alive or gladiatorBravo.is_alive:
    
            # GladiatorA's turn
            if random_event(gladiatorAlpha, gladiatorBravo):
                winner = gladiatorAlpha.name
                break
            # GladiatorB's turn
            elif random_event(gladiatorBravo, gladiatorAlpha):
                winner = gladiatorBravo.name
                break
        
        # Display the winner of the Fight!
        print(f'The winner is {winner.title()}!')
    
    
    def random_event(attacker: Gladiator, defender: Gladiator) -> bool:
        """
        This functions handles the combat event of the game.
        The program returns True if the Defender dies, False otherwise
        """
    
        # Generate a random event between 0 and 10
        event = random.randint(1, 10)
    
        # For random luck
        lucky_charms = random.randint(0, 1)
    
        # .05% chance to deliver The Five Point Palm Exploding Heart Technique!
        if event == 5 and lucky_charms:
            defender.hp = 0
            time.sleep(1)        
            print('β˜…', end='  ')
            time.sleep(.3)
            print('β˜…', end='  ')
            time.sleep(.4)
            print('β˜…', end='  ')
            time.sleep(.5)
            print('β˜…', end='  ')        
            time.sleep(1)
            # (!) Yes, the longer pause on the final death-blow is intentional! 
            print('β˜…', end='  ')
            time.sleep(1)
            print(f"\n{attacker.name} delivers the 5 point palm exploding heart technique killing {defender.name} instantly!")
            time.sleep(1)
            print('~ F A T A L I T Y! ~')
    
        # .05% chance of drinking healing potion
        elif event == 10 and lucky_charms:
            healing = int(defender.hp * .80)
            defender.hp += healing
            print(f'{defender.name} drinks magick potion and heals {healing} HP')
    
        # 20% change for Critical Attack
        elif event in range(9, 11):
            damage = int(attacker.damage * 2)
            defender.hp -= damage
            print(f"{attacker.name} landed a critical hit causing {damage} damage!")
    
        # 60% change for Hit
        elif event in range(3, 9):
            damage = int(attacker.damage * .70)
            defender.hp -= damage
            print(f"{attacker.name} lands a hit causing {damage} damage!")
    
        # 20% chance to Miss
        elif event in range(1, 3):
            print(f"{attacker.name} missed the attack, causing 0 damage!")
    
        # If defender hit points are zero or below they die!
        if defender.hp <= 0:
            defender.is_alive = False
    
        # Print results of the round
        print(f'>>> Results: {defender.name} has {defender.hp} HP\n')
        time.sleep(2)
        # The value defender.is_alive is returned this way so the function 
        # returns True if the defender dies in combat.
        return not defender.is_alive
    
    
    def main():
        # Initialize gladiators:
        gladiatorAlpha = Gladiator(name='Seraphβ˜…776', hp=1776, damage=7*70, speed=7)
        gladiatorBravo = Gladiator(name='Γ‰l Diablo', hp=6660, damage=66, speed=6)
        
        # Begin fight sequence:
        fight(gladiatorAlpha, gladiatorBravo)
    
    
    if __name__ == '__main__':
        main()
    • from dataclasses import dataclass
    • import time
    • import random
    • # Define the gladiators
    • gladiator_1 = {
    • "name": "Gregor Clegane",
    • "hp": 150,
    • "damage": 30,
    • "speed": 5,
    • }
    • gladiator_2 = {
    • "name": "Oberyn Martell",
    • "hp": 80,
    • "damage": 10,
    • "speed": 8,
    • }
    • @dataclass
    • class Gladiator:
    • name: str
    • hp: int
    • damage: int
    • speed: int
    • is_alive: bool = True
    • # Define the fight function
    • def fight(gladiator_1, gladiator_2):
    • # Print the initial status of the gladiators
    • print(f"{gladiator_1['name']} has {gladiator_1['hp']} HP and {gladiator_1['speed']} speed")
    • print(f"{gladiator_2['name']} has {gladiator_2['hp']} HP and {gladiator_2['speed']} speed")
    • print()
    • # Fight until one of the gladiators is dead
    • while gladiator_1["hp"] > 0 and gladiator_2["hp"] > 0:
    • # Determine the order of the attacks based on the speed of the gladiators
    • if gladiator_1["speed"] >= gladiator_2["speed"]:
    • attacker_1 = gladiator_1
    • attacker_2 = gladiator_2
    • else:
    • attacker_1 = gladiator_2
    • attacker_2 = gladiator_1
    • # Check for a random event at the beginning of each turn
    • random_event(attacker_1, gladiator_2)
    • random_event(attacker_2, gladiator_1)
    • # Gregor Clegane has a 10% chance to kill Oberyn in one hit
    • if attacker_2["name"] == "Gregor Clegane" and attacker_1["name"] == "Oberyn Martell" and random.randint(1, 10) == 5:
    • print(f"{attacker_2['name']} explodes {attacker_1['name']}'s skull in one hit!")
    • attacker_1["hp"] = 0
    • print("Ellaria Sand: AAAAAAAAAAAAAAAAAAAAAAH")
    • else:
    • # The attacker hits the defender
    • print(f"{attacker_1['name']} hits {attacker_2['name']}")
    • attacker_2["hp"] -= attacker_2["damage"]
    • # Print the current HP of the gladiators
    • print(f"{gladiator_1['name']} has {gladiator_1['hp']} HP")
    • print(f"{gladiator_2['name']} has {gladiator_2['hp']} HP")
    • # Print the winner of the fight
    • if gladiator_1["hp"] > 0:
    • print(f"{gladiator_1['name']} wins!")
    • else:
    • print(f"{gladiator_2['name']} wins!")
    • # Define the random_event function
    • def random_event(attacker_1, attacker_2):
    • # Generate a random number between 1 and 10
    • r = random.randint(1, 10)
    • # 10% chance of a missed attack
    • if r == 1:
    • print(f"{attacker_1['name']} missed the attack!")
    • # 20% chance of a critical hit
    • elif r <= 3:
    • print(f"{attacker_1['name']} landed a critical hit!")
    • gladiator_2["hp"] -= attacker_2["damage"] * 2
    • # Check if both gladiators have 0 or fewer hit points
    • if gladiator_1["hp"] <= 0 and gladiator_2["hp"] <= 0:
    • print("Oberyn and Gregor killed each other in an epic finish. The crowd goes wild!")
    • def fight(player_1: Gladiator, player_2: Gladiator) -> None:
    • """This function handles teh main fight sequences"""
    • winner = None
    • # Determine first attacker based on speed
    • gladiatorAlpha = max(player_1, player_2, key=lambda i: i.speed)
    • gladiatorBravo = min(player_1, player_2, key=lambda i: i.speed)
    • # Print Player vs Player
    • print(f"{gladiatorAlpha.name.title()} vs {gladiatorBravo.name}")
    • time.sleep(1)
    • print('--- FIGHT! ---\n'.center(20))
    • time.sleep(1)
    • # Main game loop:
    • while gladiatorAlpha.is_alive or gladiatorBravo.is_alive:
    • # GladiatorA's turn
    • if random_event(gladiatorAlpha, gladiatorBravo):
    • winner = gladiatorAlpha.name
    • break
    • # GladiatorB's turn
    • elif random_event(gladiatorBravo, gladiatorAlpha):
    • winner = gladiatorBravo.name
    • break
    • # Display the winner of the Fight!
    • print(f'The winner is {winner.title()}!')
    • def random_event(attacker: Gladiator, defender: Gladiator) -> bool:
    • """
    • This functions handles the combat event of the game.
    • The program returns True if the Defender dies, False otherwise
    • """
    • # Generate a random event between 0 and 10
    • event = random.randint(1, 10)
    • # For random luck
    • lucky_charms = random.randint(0, 1)
    • # .05% chance to deliver The Five Point Palm Exploding Heart Technique!
    • if event == 5 and lucky_charms:
    • defender.hp = 0
    • time.sleep(1)
    • print('β˜…', end=' ')
    • time.sleep(.3)
    • print('β˜…', end=' ')
    • time.sleep(.4)
    • print('β˜…', end=' ')
    • time.sleep(.5)
    • print('β˜…', end=' ')
    • time.sleep(1)
    • # (!) Yes, the longer pause on the final death-blow is intentional!
    • print('β˜…', end=' ')
    • time.sleep(1)
    • print(f"\n{attacker.name} delivers the 5 point palm exploding heart technique killing {defender.name} instantly!")
    • time.sleep(1)
    • print('~ F A T A L I T Y! ~')
    • # .05% chance of drinking healing potion
    • elif event == 10 and lucky_charms:
    • healing = int(defender.hp * .80)
    • defender.hp += healing
    • print(f'{defender.name} drinks magick potion and heals {healing} HP')
    • # 20% change for Critical Attack
    • elif event in range(9, 11):
    • damage = int(attacker.damage * 2)
    • defender.hp -= damage
    • print(f"{attacker.name} landed a critical hit causing {damage} damage!")
    • # 60% change for Hit
    • elif event in range(3, 9):
    • damage = int(attacker.damage * .70)
    • defender.hp -= damage
    • print(f"{attacker.name} lands a hit causing {damage} damage!")
    • # 20% chance to Miss
    • elif event in range(1, 3):
    • print(f"{attacker.name} missed the attack, causing 0 damage!")
    • # If defender hit points are zero or below they die!
    • if defender.hp <= 0:
    • defender.is_alive = False
    • # Print results of the round
    • print(f'>>> Results: {defender.name} has {defender.hp} HP\n')
    • time.sleep(2)
    • # The value defender.is_alive is returned this way so the function
    • # returns True if the defender dies in combat.
    • return not defender.is_alive
    • def main():
    • # Initialize gladiators:
    • gladiatorAlpha = Gladiator(name='Seraphβ˜…776', hp=1776, damage=7*70, speed=7)
    • gladiatorBravo = Gladiator(name='Γ‰l Diablo', hp=6660, damage=66, speed=6)
    • # Begin fight sequence:
    • fight(gladiatorAlpha, gladiatorBravo)
    • # Run the fight
    • fight(gladiator_1, gladiator_2)
    • if __name__ == '__main__':
    • main()

I made it super inefficient

Code
Diff
  • class EvenOrOdd {    
        public static String evenOrOdd(int input) {
            if (input==0){
              return "Even";
            } else if (input==1){
              return "Odd";
            } return evenOrOdd(input-2);
        }
    }
    • class EvenOrOdd {
    • class EvenOrOdd {
    • public static String evenOrOdd(int input) {
    • return input % 2 == 0 ? "Even" : "Odd";
    • if (input==0){
    • return "Even";
    • } else if (input==1){
    • return "Odd";
    • } return evenOrOdd(input-2);
    • }
    • }