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

A bit cleaner

Code
Diff
  • # from random import choice
    
    # adj = ("Leviathian","Gargantuan","Greedy","Fallen","Horrible","Twisted","Depraved","Hungry","Evil","Vengeful","Empty","Vile","Terrible", "Gluttonous")
    
    # def im_sorry():
    #     first = choice(adj)
    #     second = choice(adj)
    #     last = choice(adj)
    #     while last==first or last==second or first==second:
    #         last=choice(adj)
    #         first=choice(adj)
    #     return first+" "+second+" Garfield, The "+last + " One"
    
    from numpy.random import choice
    
    adjs = ("Leviathian","Gargantuan","Greedy","Fallen","Horrible","Twisted","Depraved","Hungry","Evil","Vengeful","Empty","Vile","Terrible", "Gluttonous")
    
    def im_sorry():
        choices = choice(adjs, 3, replace=False)
        return f"{choices[0]} {choices[1]} Garfield, The {choices[2]} One"
    • from random import choice
    • # from random import choice
    • adj = ("Leviathian","Gargantuan","Greedy","Fallen","Horrible","Twisted","Depraved","Hungry","Evil","Vengeful","Empty","Vile","Terrible", "Gluttonous")
    • # adj = ("Leviathian","Gargantuan","Greedy","Fallen","Horrible","Twisted","Depraved","Hungry","Evil","Vengeful","Empty","Vile","Terrible", "Gluttonous")
    • # def im_sorry():
    • # first = choice(adj)
    • # second = choice(adj)
    • # last = choice(adj)
    • # while last==first or last==second or first==second:
    • # last=choice(adj)
    • # first=choice(adj)
    • # return first+" "+second+" Garfield, The "+last + " One"
    • from numpy.random import choice
    • adjs = ("Leviathian","Gargantuan","Greedy","Fallen","Horrible","Twisted","Depraved","Hungry","Evil","Vengeful","Empty","Vile","Terrible", "Gluttonous")
    • def im_sorry():
    • first = choice(adj)
    • second = choice(adj)
    • last = choice(adj)
    • while last==first or last==second or first==second:
    • last=choice(adj)
    • first=choice(adj)
    • return first+" "+second+" Garfield, The "+last + " One"
    • choices = choice(adjs, 3, replace=False)
    • return f"{choices[0]} {choices[1]} Garfield, The {choices[2]} One"
Code
Diff
  • #include<iostream>
    
    int doubleValue(int x) {
        return x * 2;
    }
    
    • #include<iostream>
    • int doubleValue(int x) {
    • return x * 2;
    • }
    • int main(){
    • int x = 5; //example value
    • int result = doubleValue(x);
    • std::cout << "The double of " << x << " is " << result << std::endl;
    • return 0;
    • }
Test Cases
Diff
  • // TODO: Replace examples and use TDD by writing your own tests
    Describe(sampleTests) {
    	It(shouldBe) {
          Assert::That(doubleValue(5), Equals(10));
      }
    };
    • // TODO: Replace examples and use TDD by writing your own tests
    • Describe(any_group_name_you_want)
    • {
    • It(should_do_something)
    • {
    • Assert::That("some value", Equals("another value"));
    • }
    • };
    • Describe(sampleTests) {
    • It(shouldBe) {
    • Assert::That(doubleValue(5), Equals(10));
    • }
    • };

requires O(n) extra space

Code
Diff
  • memo={0:"Even"}
    curr=0
    isEven=True
    def even_or_odd(n):
        def enclosed():
            global memo
            global curr
            global isEven
            nonlocal n
            if n in memo:
                return memo[n]
            while curr<=n:
                memo[curr]= "Even" if isEven else "Odd"
                curr+=1
                isEven=not isEven
            return memo[n]
        return enclosed()
    
    # memo={}
    # def even_or_odd(n):
    #     def enclosed():
    #         global memo
    #         nonlocal n
    #         if n in memo:
    #             return memo[n]
    #         memo[n]= "Odd" if n&1 else "Even"
    #         return memo[n]
    #     print(memo)
    #     return enclosed()
    
    
    # memo={0:"Even"}
    # curr=0
    # isEven=True
    # def even_or_odd(n):
    #     global isEven
    #     global curr
    #     if n in memo:
    #         return memo[n]
    #     while curr<=n:
    #         memo[curr]="Even" if isEven else "Odd"
    #         curr+=1
    #         isEven=not isEven
    #     return memo[n]
    
    #
    
    
    
    
    • even_or_odd = lambda x: "Even" if x%2==0 else "Odd"
    • memo={0:"Even"}
    • curr=0
    • isEven=True
    • def even_or_odd(n):
    • def enclosed():
    • global memo
    • global curr
    • global isEven
    • nonlocal n
    • if n in memo:
    • return memo[n]
    • while curr<=n:
    • memo[curr]= "Even" if isEven else "Odd"
    • curr+=1
    • isEven=not isEven
    • return memo[n]
    • return enclosed()
    • # memo={}
    • # def even_or_odd(n):
    • # def enclosed():
    • # global memo
    • # nonlocal n
    • # if n in memo:
    • # return memo[n]
    • # memo[n]= "Odd" if n&1 else "Even"
    • # return memo[n]
    • # print(memo)
    • # return enclosed()
    • # memo={0:"Even"}
    • # curr=0
    • # isEven=True
    • # def even_or_odd(n):
    • # global isEven
    • # global curr
    • # if n in memo:
    • # return memo[n]
    • # while curr<=n:
    • # memo[curr]="Even" if isEven else "Odd"
    • # curr+=1
    • # isEven=not isEven
    • # return memo[n]
    • #
Fundamentals
Logic

It ain't getting any smaller than this (I think)

Code
Diff
  • using System.Linq;class Math{public static T Max<T>(params T[]p)=>p.Max();}
    • class Math{public static T Max<T>(params T[]p)where T:System.IComparable<T>{foreach(T a in p)p[0]=p[0].CompareTo(a)<0?a:p[0];return p[0];}}
    • using System.Linq;class Math{public static T Max<T>(params T[]p)=>p.Max();}

better lol

Code
Diff
  • public static class Kata 
    {
      public static int SameCase(char a, char b) =>
          !char.IsLetter(a) || !char.IsLetter(b) ? -1 :
          char.IsUpper(a) == char.IsUpper(b) ? 1 : 0;
    }
    • public static class Kata
    • {
    • public static int SameCase(char a, char b)
    • {
    • if (!char.IsLetter(a) || !char.IsLetter(b))
    • return -1;
    • return char.IsUpper(a) == char.IsUpper(b) ? 1 : 0;
    • }
    • public static int SameCase(char a, char b) =>
    • !char.IsLetter(a) || !char.IsLetter(b) ? -1 :
    • char.IsUpper(a) == char.IsUpper(b) ? 1 : 0;
    • }
Code
Diff
  • function returnhundred(clаss = "-🤓") {
        return Math.floor(
            doMath(f, 0.0504, Math.PI ** (clаss.length - 1) * Math.E - Math.log(gamma(10.7)))
        );
    };
    
    const gamma = x => {
        if (x < 0.5) {
            return Math.PI / (Math.sin(Math.PI * x) * gamma(1 - x));
        } else {
            x -= 1;
            let l = 0.99999999999980993;
            const l0 = [
                676.5203681218851, -1259.1392167224028, 771.32342877765313,
                -176.61502916214059, 12.507343278686905, -0.13857109526572012,
                9.9843695780195716e-6, 1.5056327351493116e-7,
            ];
            for (let i = 0; i < 8; i++) {
                l += l0[i] / (x + i + 1);
            }
            const t = x + 7.5;
            return Math.sqrt(2 * Math.PI) * Math.pow(t, x + 0.5) * Math.exp(-t) * l;
        }
    };
    
    const doMath = (f, start, end) => {
        let res = 0;
        const base = (end - start) / gamma(0.0000001);
        for (let i = start; i < end; i += base) {
            const [left, right] = [f(i), f(i + base)];
            res += (left + right) / "🤓".length;
        }
        return Math.ceil(base * res);
    };
    
    const f = x => {
        return Math.abs(
            Math.exp(
                "�".length *
                Math.sinh(
                    2 *
                    Math.cos(
                        (Math.tan(x) % gamma(Math.PI)) * Math.sqrt(314)
                    )
                )
            ) /
            ((1 / 20) * 16)
        );
    }
    • returnhundred=ಠ_ಠ=>100
    • function returnhundred(clаss = "-🤓") {
    • return Math.floor(
    • doMath(f, 0.0504, Math.PI ** (clаss.length - 1) * Math.E - Math.log(gamma(10.7)))
    • );
    • };
    • const gamma = x => {
    • if (x < 0.5) {
    • return Math.PI / (Math.sin(Math.PI * x) * gamma(1 - x));
    • } else {
    • x -= 1;
    • let l = 0.99999999999980993;
    • const l0 = [
    • 676.5203681218851, -1259.1392167224028, 771.32342877765313,
    • -176.61502916214059, 12.507343278686905, -0.13857109526572012,
    • 9.9843695780195716e-6, 1.5056327351493116e-7,
    • ];
    • for (let i = 0; i < 8; i++) {
    • l += l0[i] / (x + i + 1);
    • }
    • const t = x + 7.5;
    • return Math.sqrt(2 * Math.PI) * Math.pow(t, x + 0.5) * Math.exp(-t) * l;
    • }
    • };
    • const doMath = (f, start, end) => {
    • let res = 0;
    • const base = (end - start) / gamma(0.0000001);
    • for (let i = start; i < end; i += base) {
    • const [left, right] = [f(i), f(i + base)];
    • res += (left + right) / "🤓".length;
    • }
    • return Math.ceil(base * res);
    • };
    • const f = x => {
    • return Math.abs(
    • Math.exp(
    • "�".length *
    • Math.sinh(
    • 2 *
    • Math.cos(
    • (Math.tan(x) % gamma(Math.PI)) * Math.sqrt(314)
    • )
    • )
    • ) /
    • ((1 / 20) * 16)
    • );
    • }

Avoid arbitary code execution

Code
Diff
  • function Calculator {
        param (
            [int]$n1,
            [ValidateSet("+", "*", "-")]
            [string]$s,
            [int]$n2
        )
        Invoke-Expression ("$n1 $s $n2")
    }
    • function Calculator ($n1,$s,$n2 ){
    • Invoke-Expression ("$n1 $s $n2")
    • function Calculator {
    • param (
    • [int]$n1,
    • [ValidateSet("+", "*", "-")]
    • [string]$s,
    • [int]$n2
    • )
    • Invoke-Expression ("$n1 $s $n2")
    • }