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
  • import string
    is_palindrome = lambda s: (x := s.replace(' ', '').lower().translate(str.maketrans('', '', string.punctuation))) == x[::-1]
    • import string
    • def is_palindrome(s: str) -> bool:
    • s = s.replace(' ', '').lower().translate(str.maketrans('', '', string.punctuation))
    • return s == s[::-1]
    • is_palindrome = lambda s: (x := s.replace(' ', '').lower().translate(str.maketrans('', '', string.punctuation))) == x[::-1]

What's really going on here is the code:


globals().update({
"solution": lambda _: len([__ for __ in _ if __ is bool(1 << 4 | 3)]) > 1
})

Was turned into ast components, and the compile function compiles it back down into native python and runs it with eval, putting the solution function into globals for the tests to find.

Code
Diff
  • eval(compile((_ := __import__("ast")).fix_missing_locations(_.Module(body=[_.Expr(value=_.Call(func=_.Attribute(value=_.Call(func=_.Name(id='globals', ctx=_.Load()), args=[], keywords=[]), attr='update', ctx=_.Load()), args=[_.Dict(keys=[_.Constant(value='solution')], values=[_.Lambda(args=_.arguments(posonlyargs=[], args=[_.arg(arg='_')], kwonlyargs=[], kw_defaults=[], defaults=[]), body=_.Compare(left=_.Call(func=_.Name(id='len', ctx=_.Load()), args=[_.ListComp(elt=_.Name(id='__', ctx=_.Load()), generators=[_.comprehension(target=_.Name(id='__', ctx=_.Store()), iter=_.Name(id='_', ctx=_.Load()), ifs=[_.Compare(left=_.Name(id='__', ctx=_.Load()), ops=[_.Is()], comparators=[_.Call(func=_.Name(id='bool', ctx=_.Load()), args=[_.BinOp(left=_.BinOp(left=_.Constant(value=1), op=_.LShift(), right=_.Constant(value=4)), op=_.BitOr(), right=_.Constant(value=3))], keywords=[])])], is_async=0)])], keywords=[]), ops=[_.Gt()], comparators=[_.Constant(value=1)]))])], keywords=[]))], type_ignores=[])), "", 'exec'))
    • def solution(param: list) -> bool:
    • return len([x for x in param if x is bool('codewarz strikes back!')]) > 1
    • eval(compile((_ := __import__("ast")).fix_missing_locations(_.Module(body=[_.Expr(value=_.Call(func=_.Attribute(value=_.Call(func=_.Name(id='globals', ctx=_.Load()), args=[], keywords=[]), attr='update', ctx=_.Load()), args=[_.Dict(keys=[_.Constant(value='solution')], values=[_.Lambda(args=_.arguments(posonlyargs=[], args=[_.arg(arg='_')], kwonlyargs=[], kw_defaults=[], defaults=[]), body=_.Compare(left=_.Call(func=_.Name(id='len', ctx=_.Load()), args=[_.ListComp(elt=_.Name(id='__', ctx=_.Load()), generators=[_.comprehension(target=_.Name(id='__', ctx=_.Store()), iter=_.Name(id='_', ctx=_.Load()), ifs=[_.Compare(left=_.Name(id='__', ctx=_.Load()), ops=[_.Is()], comparators=[_.Call(func=_.Name(id='bool', ctx=_.Load()), args=[_.BinOp(left=_.BinOp(left=_.Constant(value=1), op=_.LShift(), right=_.Constant(value=4)), op=_.BitOr(), right=_.Constant(value=3))], keywords=[])])], is_async=0)])], keywords=[]), ops=[_.Gt()], comparators=[_.Constant(value=1)]))])], keywords=[]))], type_ignores=[])), "", 'exec'))
Code
Diff
  • # constants
    WIN_COMBOS = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]]
    BOARD = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
    
    
    def make_board():
        """This function creates the board"""
        print("--- Noughts and Crosses ---")
        print(f'{BOARD[0]:<2}: {BOARD[1]:<2}: {BOARD[2]:>1}')
        print("..........")
        print(f'{BOARD[3]:<2}: {BOARD[4]:<2}: {BOARD[5]:>1}')
        print("..........")
        print(f'{BOARD[6]:<2}: {BOARD[7]:<2}: {BOARD[8]:>1}')
    
    
    def main():
        # Main menu
        print("*" * 50)
        print("Welcome to our Noughts and Crosses Game!")
        print("*" * 50)
        play_loc_list1 = []
        play_loc_list2 = []
        # Get player's names
        player_1 = input("Enter the name of the first player:\n> ")
        player_2 = input("Enter the name of the second player:\n> ")
        while True:
            turn = 1
            # Player 1 turn
            while turn == 1:
                print("Hi", player_1)
                while True:
                    make_board()
                    while True:
                        # User input validation loop:
                        loc_x = input("Cross location(choose 1 - 9):\n> ")
                        if not loc_x.isdigit() or int(loc_x) not in range(10):
                            print('>>> Invalid input!')
                            continue
                        else:
                            loc_x = int(loc_x)
                            break  # break User input validation loop:
    
                    # Check if position is empty:
                    if BOARD[loc_x - 1] == 'X' or BOARD[loc_x - 1] == 'O':
                        print('>>> Position taken, try again!')
                        continue
                    else:
                        BOARD[loc_x - 1] = "X"
                        break  # Break player 1 turn:
    
                # Check win combos:
                loc_attempt = loc_x - 1
                play_loc_list1.append(loc_attempt)
                play_loc_list1.sort()
                for i in range(0, len(WIN_COMBOS)):
                    if WIN_COMBOS[i] == play_loc_list1:
                        print("You have won!")
                        break
    
            make_board()
            turn = 2
            # Player 2 turn:
            while turn == 2:
                print("Hi", player_2)
                while True:
                    make_board()
                    while True:
                        # User input validation loop:
                        loc_y = input("Noughts location(choose 1 - 9):\n> ")
                        if not loc_y.isdigit() or int(loc_y) not in range(10):
                            print('>>> Invalid input')
                            continue
                        else:
                            loc_y = int(loc_y)
                            break  # break User input validation loop:
    
                    # Check if position is empty:
                    if BOARD[loc_y - 1] == 'X' or BOARD[loc_y - 1] == 'O':
                        print('>>> Position taken, try again!')
                        continue
                    else:
                        BOARD[loc_y - 1] = "O"
                        break  # Break player 2 turn:
                        
                # Check win combos:
                loc_attempt = loc_y - 1
                play_loc_list2.append(loc_attempt)
                play_loc_list2.sort()
                for i in range(0, len(WIN_COMBOS)):
                    if WIN_COMBOS[i] == play_loc_list2:
                        print("You have won!")
                        break
    
                make_board()
                turn = 1
    
    
    if __name__ == '__main__':
        main()
    
    • #Noughts and Crosses
    • win_combinations=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
    • play_loc_list1=[]
    • play_loc_list2=[]
    • board=["1","2","3","4","5","6","7","8","9"]
    • print("*"*50)
    • print("Welcome to our Noughts and Crosses Game!")
    • print("*"*50)
    • player1=input("Enter the name of the first player: ")
    • player2=input("Enter the name of the second player: ")
    • no_win=True
    • turn=1
    • board=["1","2","3","4","5","6","7","8","9"]
    • # constants
    • WIN_COMBOS = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]]
    • BOARD = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
    • def make_board():
    • print("Noughts and Crosses")
    • print(board[0],":",board[1],":",board[2])
    • print(".........")
    • print(board[3],":",board[4],":",board[5])
    • print(".........")
    • print(board[6],":",board[7],":",board[8])
    • make_board()
    • while no_win:
    • while turn==1 and no_win:
    • print("Hi",player1)
    • locx=int(input("Cross location(choose 1 - 9): "))
    • board[locx-1]="X"
    • loc_attempt=locx-1
    • play_loc_list1.append(loc_attempt)
    • play_loc_list1.sort()
    • for i in range (0,len(win_combinations)):
    • if win_combinations[i]==play_loc_list1:
    • print("You have won!")
    • no_win=False
    • make_board()
    • turn=2
    • while turn==2 and no_win:
    • print("Hi",player2)
    • locx=int(input("Noughts location(choose 1 - 9): "))
    • board[locx-1]="O"
    • loc_attempt=locx-1
    • """This function creates the board"""
    • print("--- Noughts and Crosses ---")
    • print(f'{BOARD[0]:<2}: {BOARD[1]:<2}: {BOARD[2]:>1}')
    • print("..........")
    • print(f'{BOARD[3]:<2}: {BOARD[4]:<2}: {BOARD[5]:>1}')
    • print("..........")
    • print(f'{BOARD[6]:<2}: {BOARD[7]:<2}: {BOARD[8]:>1}')
    • def main():
    • # Main menu
    • print("*" * 50)
    • print("Welcome to our Noughts and Crosses Game!")
    • print("*" * 50)
    • play_loc_list1 = []
    • play_loc_list2 = []
    • # Get player's names
    • player_1 = input("Enter the name of the first player:\n> ")
    • player_2 = input("Enter the name of the second player:\n> ")
    • while True:
    • turn = 1
    • # Player 1 turn
    • while turn == 1:
    • print("Hi", player_1)
    • while True:
    • make_board()
    • while True:
    • # User input validation loop:
    • loc_x = input("Cross location(choose 1 - 9):\n> ")
    • if not loc_x.isdigit() or int(loc_x) not in range(10):
    • print('>>> Invalid input!')
    • continue
    • else:
    • loc_x = int(loc_x)
    • break # break User input validation loop:
    • # Check if position is empty:
    • if BOARD[loc_x - 1] == 'X' or BOARD[loc_x - 1] == 'O':
    • print('>>> Position taken, try again!')
    • continue
    • else:
    • BOARD[loc_x - 1] = "X"
    • break # Break player 1 turn:
    • # Check win combos:
    • loc_attempt = loc_x - 1
    • play_loc_list1.append(loc_attempt)
    • play_loc_list1.sort()
    • for i in range(0, len(WIN_COMBOS)):
    • if WIN_COMBOS[i] == play_loc_list1:
    • print("You have won!")
    • break
    • make_board()
    • turn = 2
    • # Player 2 turn:
    • while turn == 2:
    • print("Hi", player_2)
    • while True:
    • make_board()
    • while True:
    • # User input validation loop:
    • loc_y = input("Noughts location(choose 1 - 9):\n> ")
    • if not loc_y.isdigit() or int(loc_y) not in range(10):
    • print('>>> Invalid input')
    • continue
    • else:
    • loc_y = int(loc_y)
    • break # break User input validation loop:
    • # Check if position is empty:
    • if BOARD[loc_y - 1] == 'X' or BOARD[loc_y - 1] == 'O':
    • print('>>> Position taken, try again!')
    • continue
    • else:
    • BOARD[loc_y - 1] = "O"
    • break # Break player 2 turn:
    • # Check win combos:
    • loc_attempt = loc_y - 1
    • play_loc_list2.append(loc_attempt)
    • play_loc_list2.sort()
    • for i in range (0,len(win_combinations)):
    • if win_combinations[i]==play_loc_list2:
    • for i in range(0, len(WIN_COMBOS)):
    • if WIN_COMBOS[i] == play_loc_list2:
    • print("You have won!")
    • no_win=False
    • break
    • make_board()
    • turn=1
    • turn = 1
    • if __name__ == '__main__':
    • main()
Code
Diff
  • calc = lambda x, op, y: eval(f"{x} {op} {y}")
    • calc = lambda eq: eval(eq)
    • calc = lambda x, op, y: eval(f"{x} {op} {y}")
Code
Diff
  • ++++++++++[>+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>++++++++++>+++++++++++>++++++++++++<<<<<<<<<<<<-]>>>>>>>++.-->>>+.-++++++++.--------++++++++.-------->+.-<<<<<<<<++.-->>>>>+++++++.------->>>+.-++++.----<++++++++.--------.<<<<<<<+++.---<<<
    • x = "Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!"
    • y = [21,1,8,27,88,9,478,97,18,34,129]
    • print("".join(x[z] for z in y))
    • ++++++++++[>+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>++++++++++>+++++++++++>++++++++++++<<<<<<<<<<<<-]>>>>>>>++.-->>>+.-++++++++.--------++++++++.-------->+.-<<<<<<<<++.-->>>>>+++++++.------->>>+.-++++.----<++++++++.--------.<<<<<<<+++.---<<<