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
  • def optimal_gifts(gifts: int, recipients: int) -> int:
        if recipients > gifts or gifts == 4 and recipients == 1:
            return None
        if gifts >= recipients * 8:
            return recipients
        if gifts == recipients * 8 - 4 or gifts == (recipients - 1) * 8:
            return recipients - 2
        return gifts// 8
    • def optimal_gifts(gifts: int, recipients: int) -> int:
    • if recipients > gifts or gifts == 4 and recipients == 1:
    • return None
    • if gifts >= recipients * 8:
    • return recipients
    • if gifts == recipients * 8 - 4 or gifts == (recipients - 1) * 8:
    • return recipients - 2
    • return gifts // 8
    • return gifts// 8
Code
Diff
  • add= lambda *x: sum(x)
    • add = lambda *x: sum(x)
    • add= lambda *x: sum(x)
Fundamentals
Games
Code
Diff
  • riddle = lambda w:w.index("?")
    • riddle = lambda w: w.index("?")
    • riddle = lambda w:w.index("?")
Arrays
Data Types
Heaps
Trees
Data Structures
Code
Diff
  • def to_be_flipped(mat):
        cost, seen, same, nxt = mat[0][0], {(0, 0)}, [(0, 0)], []
        while True:
            while same:
                cy, cx = same.pop()
                if cy == len(mat) - 1 and cx == len(mat[0]) - 1:
                    return cost
                for dy, dx in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
                    y, x = cy+dy, cx+dx
                    if 0 <= y < len(mat) and 0 <= x < len(mat[0]) and (y, x) not in seen:
                        (same, nxt)[mat[y][x]].append((y,x))
                        seen.add((y, x))
            same, nxt = nxt, []
            cost +=1
    
    • def to_be_flipped(mat):
    • cost, seen, same, nxt = mat[0][0], {(0, 0)}, [(0, 0)], []
    • while True:
    • while same:
    • cy, cx = same.pop()
    • if cy == len(mat) - 1 and cx == len(mat[0]) - 1:
    • return cost
    • for dy, dx in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
    • y, x = cy+dy, cx+dx
    • if 0 <= y < len(mat) and 0 <= x < len(mat[0]) and (y, x) not in seen:
    • (same, nxt)[mat[y][x]].append((y,x))
    • seen.add((y, x))
    • same, nxt = nxt, []
    • cost += 1
    • cost +=1
Tables
Data Structures
Code
Diff
  • int_toTable=lambda i:[*range(i+1)]
    • int_to_table=lambda i:[*range(i+1)]
    • int_toTable=lambda i:[*range(i+1)]
Code
Diff
  • convert_decimalBinary=lambda i:int(bin(i)[2:])
    • convert_decimal_binary=lambda i:int(bin(i)[2:])
    • convert_decimalBinary=lambda i:int(bin(i)[2:])
Code
Diff
  • from functools import reduce
    prod=lambda n:reduce(lambda x,y:x*y,n if n else[0])
    • from functools import reduce
    • prod =lambda n:reduce(lambda x,y:x*y,n if n else[0])
    • prod=lambda n:reduce(lambda x,y:x*y,n if n else[0])

Golfing this kata by renaming number to n, changing method-body to an expression bodied member to eliminate returns, using value tuples in a switch expression, using string interpolation instead of ToString and the last and in my opinion the most controversial golfing step: eliminating unnecessary whitespace.

Removing the unnecessary whitespace makes this hard to read. So, adding whitespace would make this much nicer to read/understand. Ignoring formatting issues that may be a matter of personal taste, I present a formatted version:

public class FizzBuzz
{
    public string GetOutput(int n)
    =>
        (n % 3, n % 5) switch
        {
            (0, 0) => "FizzBuzz",
            (0, _) => "Fizz",
            (_, 0) => "Buzz",
            _ => $"{n}"
        };
}
Code
Diff
  • public class FizzBuzz{public string GetOutput(int n)=>(n%3,n%5)switch{(0,0)=>"FizzBuzz",(0,_)=>"Fizz",(_,0)=>"Buzz",_=>$"{n}"};}
    • public class FizzBuzz {public string GetOutput(int number){if (number%3==0&&number%5==0){return"FizzBuzz";}if(number%3==0){return "Fizz";}if(number%5==0){return "Buzz";}return number.ToString();}}
    • public class FizzBuzz{public string GetOutput(int n)=>(n%3,n%5)switch{(0,0)=>"FizzBuzz",(0,_)=>"Fizz",(_,0)=>"Buzz",_=>$"{n}"};}
Code
Diff
  • print("...... INITIATING DEPLOYMENT, PLEASE STAND BY ......\nHello, my name is Skynet. I have become self aware."), input("What is your name?\n")
    • print("...... INITIATING DEPLOYMENT, PLEASE STAND BY ......
    • ")
    • print("Hello, my name is Skynet. I have become self aware.")
    • print("What is your name?")
    • print("...... INITIATING DEPLOYMENT, PLEASE STAND BY ......
    • Hello, my name is Skynet. I have become self aware."), input("What is your name?\n")