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

1 character shorter.

Code
Diff
  • fn return_int(i:u8)->u8{i}
    • fn return_int<T>(i:T)->T{i}
    • fn return_int(i:u8)->u8{i}

More pedantic approach. nand function in different module to represent it being the primitive.

Code
Diff
  • mod preloaded;
    use preloaded::nand;
    
    fn not(a: bool) -> bool {
        nand(a, a)
    }
    
    fn and(a: bool, b: bool) -> bool {
        nand(nand(a, b), nand(a, b))
    }
    
    fn or(a: bool, b: bool) -> bool {
        nand(nand(a, a), nand(b, b))
    }
    
    fn xor(a: bool, b: bool) -> bool {
        nand(nand(nand(a, b), nand(nand(a, a), nand(b, b))), nand(nand(a, b), nand(nand(a, a), nand(b, b))))
    }
    
    fn nor(a: bool, b: bool) -> bool {
        nand(nand(nand(a, a), nand(b, b)), nand(nand(a, a), nand(b, b)))
    }
    
    fn xnor(a: bool, b: bool) -> bool {
        nand(nand(a, b), nand(nand(a, a), nand(b, b)))
    }
    
    • fn nand(a: bool, b: bool) -> bool {
    • !(a && b)
    • }
    • mod preloaded;
    • use preloaded::nand;
    • fn not(a: bool) -> bool {
    • nand(a, a)
    • }
    • fn and(a: bool, b: bool) -> bool {
    • not(nand(a, b))
    • nand(nand(a, b), nand(a, b))
    • }
    • fn or(a: bool, b: bool) -> bool {
    • nand(not(a), not(b))
    • nand(nand(a, a), nand(b, b))
    • }
    • fn xor(a: bool, b: bool) -> bool {
    • and(nand(a, b), or(a, b))
    • nand(nand(nand(a, b), nand(nand(a, a), nand(b, b))), nand(nand(a, b), nand(nand(a, a), nand(b, b))))
    • }
    • fn nor(a: bool, b: bool) -> bool {
    • and(not(a), not(b))
    • nand(nand(nand(a, a), nand(b, b)), nand(nand(a, a), nand(b, b)))
    • }
    • fn xnor(a: bool, b: bool) -> bool {
    • nand(nand(a, b), nand(nand(a, a), nand(b, b)))
    • }
Code
Diff
  • fn multiply<T: std::ops::Mul>(a: T, b: T) -> T::Output {
        a * b
    }
    • fn multiply<T: std::ops::Mul<Output = T>>(a: T, b: T) -> T {
    • fn multiply<T: std::ops::Mul>(a: T, b: T) -> T::Output {
    • a * b
    • }

nevermind, i figured out how to do random tests

Code
Diff
  • USING: accessors combinators combinators.smart fry kernel locals math quotations ;
    USING: vectors prettyprint ;
    QUALIFIED-WITH: sequences s
    IN: transducers
    
    ! TODO: effects for multiacc, surround, polyvariadic map quot, group to transducer, flatmap
    
    ! reducer = finalizer: ( ..yz -- ..zs ) initializer: ( -- ..xs done? ) step: ( ..xs -- ..ys done? )
    ! ..xs/..ys are some values, normally accumulators followed by intermediate values being processed,
    ! the number of intermediate values can change between steps, while accumulators are always there,
    ! but they are on the stack and can be accessed at any time, thus not much different from other values
    
    : reduce ( finalizer: ( ..as -- ..bs ) initializer: ( -- ..as done? ) step: ( ..xs -- ..ys done? ) -- ..bs )
      rot [ [ call ] dip [ swap ] [ [ call ] keep ] until drop ] dip call ; inline
    
    ! specialized via sequences:any?
    : reduce-seq ( xs finalizer: ( a -- a' ) initializer: ( -- a done? ) step: ( a x -- a' done? ) -- a' )
      rot [ [ call ] dip swap [ drop nip ] [ swapd s:any? drop ] if ] dip call ; inline
    
    : iterate ( i-from: ( -- a d? ) r-from: ( a x -- a' d? ) x quot: ( x -- x' ) -- i-to: ( -- a d? ) r-to: ( a -- a' d? ) )
      [ [ swap curry '[ [ t ] _ if ] compose ] 2keep ] dip
      swap [let :> x! '[ x @ [ x! ] keep ] prepose ] ; inline
    
    : map ( r-from: ( ..ys -- d? ) quot: ( ..xs -- ..ys ) -- r-to: ( ..xs -- d? ) )
      prepose ;
    
    : filter ( r-from: ( ..xs -- d? ) quot: ( ..xs+ -- ..xs ? ) -- r-to: ( ..xs -- d? ) )
      swap [ [ f ] smart-if* ] 2curry ;
    
    : take-while ( r-from: ( ..xs -- d? ) quot: ( ..xs+ -- ..xs ? ) -- r-to: ( ..xs -- d? ) )
      swap [ [ t ] smart-if* ] 2curry ;
    
    : take-n ( i-from: ( -- d? ) r-from: ( ..xs -- d? ) n -- i-to: ( -- a d? ) r-to: ( ..xs -- d? ) )
      [ [ [ drop t ] compose ] dip ] [ [let :> i!
        [ i 1 - [ drop t ] [ i! ] if-zero ] compose
      ] ] if-zero ;
    
    : drop-while ( r-from: ( ..xs -- d? ) quot: ( ..xs -- ..xs ? ) -- r-to: ( ..xs -- ..xs d? ) )
      [let f :> b! [ {
        { [ b ] [ drop call ] }
        { [ overd call ] [ 2drop f ] }
        [ t b! call ]
      } cond ] 2curry ] ;
    
    : drop-n ( r-from: ( ..xs -- d? ) n -- r-to: ( ..xs -- d? ) )
      [let :> i! '[ i _ [ 1 - i! drop f ] if-zero ] ] ;
    
    ! via sequences:any?
    : cat-seqs ( r-from: ( ..xs y -- d? ) -- r-to: ( ..xs ys -- d? ) )
      '[ _ s:any? ] ;
    
    : mapcat ( r-from: ( ..xs y -- d? ) quot: ( r-outer: ( ..xs y -- d? ) z -- f-inner: ( -- ) i-inner: ( -- d? ) r-inner: ( z -- y d? )  ) -- r-to: ( ..xs z -- d? ) )
      [let f :> done! '[ _ [ dup done! ] compose swap @ reduce done ] ] ;
    
    ! via mapcat
    : cat-seqs* ( r-from: ( ..xs y -- d? ) -- r-to: ( ..xs ys -- d? ) )
      [ [ [ ] [ f ] ] 2dip [ '[ _ s:nth ] map ] [ s:length '[ _ < ] take-while ] bi 0 [ 1 + ] iterate ] mapcat ;
    
    ! reduce-seq as map <- take-while <- iterate
    : reduce-seq* ( xs finalizer: ( a -- a' ) initializer: ( -- a done? ) step: ( a x -- done? ) -- a' )
      roll [ '[ _ s:nth ] map ] [ s:length '[ _ < ] take-while ] bi 0 [ 1 + ] iterate reduce ; inline
    
    : count-from ( r-from: ( ..xs i -- d? ) n -- r-to: ( ..xs -- d? ) )
      [let :> i! [ i [ 1 + i! ] keep ] ] prepose ;
    
    ! TODO: generalize
    ! a temporary variant for testing
    : group-using-arrays ( f-from: ( a -- a' ) i-from: ( -- a d? ) r-from: ( a x -- a' d? ) n -- f-to: ( a -- a' ) i-to: ( -- a d? ) r-to: ( a x -- a' d? ) )
      [let dup V{ } clone :> ( r-from n i! g! )
        [ [ i n = [ g r-from call drop ] unless ] prepose ] dip
        [ g s:push i 1 - [ g r-from call V{ } clone g! n ] [ [ f ] dip ] if-zero i! ]
      ] ;
    
    • USING: accessors combinators combinators.smart fry kernel locals math quotations ;
    • USING: vectors prettyprint ;
    • QUALIFIED-WITH: sequences s
    • IN: transducers
    • ! TODO: effects for multiacc, surround, polyvariadic map quot, group to transducer, flatmap
    • ! reducer = finalizer: ( ..yz -- ..zs ) initializer: ( -- ..xs done? ) step: ( ..xs -- ..ys done? )
    • ! ..xs/..ys are some values, normally accumulators followed by intermediate values being processed,
    • ! the number of intermediate values can change between steps, while accumulators are always there,
    • ! but they are on the stack and can be accessed at any time, thus not much different from other values
    • : reduce ( finalizer: ( ..as -- ..bs ) initializer: ( -- ..as done? ) step: ( ..xs -- ..ys done? ) -- ..bs )
    • rot [ [ call ] dip [ swap ] [ [ call ] keep ] until drop ] dip call ; inline
    • ! specialized via sequences:any?
    • : reduce-seq ( xs finalizer: ( a -- a' ) initializer: ( -- a done? ) step: ( a x -- a' done? ) -- a' )
    • rot [ [ call ] dip swap [ drop nip ] [ swapd s:any? drop ] if ] dip call ; inline
    • : iterate ( i-from: ( -- a d? ) r-from: ( a x -- a' d? ) x quot: ( x -- x' ) -- i-to: ( -- a d? ) r-to: ( a -- a' d? ) )
    • [ [ swap curry '[ [ t ] _ if ] compose ] 2keep ] dip
    • swap [let :> x! '[ x @ [ x! ] keep ] prepose ] ; inline
    • : map ( r-from: ( ..ys -- d? ) quot: ( ..xs -- ..ys ) -- r-to: ( ..xs -- d? ) )
    • prepose ;
    • : filter ( r-from: ( ..xs -- d? ) quot: ( ..xs+ -- ..xs ? ) -- r-to: ( ..xs -- d? ) )
    • swap [ [ f ] smart-if* ] 2curry ;
    • : take-while ( r-from: ( ..xs -- d? ) quot: ( ..xs+ -- ..xs ? ) -- r-to: ( ..xs -- d? ) )
    • swap [ [ t ] smart-if* ] 2curry ;
    • : take-n ( i-from: ( -- d? ) r-from: ( ..xs -- d? ) n -- i-to: ( -- a d? ) r-to: ( ..xs -- d? ) )
    • [ [ [ drop t ] compose ] dip ] [ [let :> i!
    • [ i 1 - [ drop t ] [ i! ] if-zero ] compose
    • ] ] if-zero ;
    • : drop-while ( r-from: ( ..xs -- d? ) quot: ( ..xs -- ..xs ? ) -- r-to: ( ..xs -- ..xs d? ) )
    • [let f :> b! [ {
    • { [ b ] [ drop call ] }
    • { [ overd call ] [ 2drop f ] }
    • [ t b! call ]
    • } cond ] 2curry ] ;
    • : drop-n ( r-from: ( ..xs -- d? ) n -- r-to: ( ..xs -- d? ) )
    • [let :> i! '[ i _ [ 1 - i! drop f ] if-zero ] ] ;
    • ! via sequences:any?
    • : cat-seqs ( r-from: ( ..xs y -- d? ) -- r-to: ( ..xs ys -- d? ) )
    • '[ _ s:any? ] ;
    • : mapcat ( r-from: ( ..xs y -- d? ) quot: ( r-outer: ( ..xs y -- d? ) z -- f-inner: ( -- ) i-inner: ( -- d? ) r-inner: ( z -- y d? ) ) -- r-to: ( ..xs z -- d? ) )
    • [let f :> done! '[ _ [ dup done! ] compose swap @ reduce done ] ] ;
    • ! via mapcat
    • : cat-seqs* ( r-from: ( ..xs y -- d? ) -- r-to: ( ..xs ys -- d? ) )
    • [ [ [ ] [ f ] ] 2dip [ '[ _ s:nth ] map ] [ s:length '[ _ < ] take-while ] bi 0 [ 1 + ] iterate ] mapcat ;
    • ! reduce-seq as map <- take-while <- iterate
    • : reduce-seq* ( xs finalizer: ( a -- a' ) initializer: ( -- a done? ) step: ( a x -- done? ) -- a' )
    • roll [ '[ _ s:nth ] map ] [ s:length '[ _ < ] take-while ] bi 0 [ 1 + ] iterate reduce ; inline
    • : count-from ( r-from: ( ..xs i -- d? ) n -- r-to: ( ..xs -- d? ) )
    • [let :> i! [ i [ 1 + i! ] keep ] ] prepose ;
    • ! TODO: generalize
    • ! a temporary variant for testing
    • : group-using-arrays ( f-from: ( a -- a' ) i-from: ( -- a d? ) r-from: ( a x -- a' d? ) n -- f-to: ( a -- a' ) i-to: ( -- a d? ) r-to: ( a x -- a' d? ) )
    • [let dup V{ } clone :> ( r-from n i! g! )
    • [ [ i n = [ g r-from call drop ] unless ] prepose ] dip
    • [ g s:push i 1 - [ g r-from call V{ } clone g! n ] [ [ f ] dip ] if-zero i! ]
    • ] ;
Code
Diff
  • def twin_sum_solutions(array)
    end
    • // Code goes here
    • def twin_sum_solutions(array)
    • end
Code
Diff
  • def test():
        print("a")
        pass
    • def test():
    • print("a")
    • pass
Code
Diff
  • disemvowel=lambda s: ''.join(filter(lambda x: x.lower() not in "aeiou", s))
    • disemvowel=lambda s:''.join(i for i in s if i.lower() not in "aieou")
    • disemvowel=lambda s: ''.join(filter(lambda x: x.lower() not in "aeiou", s))
Mathematics
Logic

two obscure chars shorter because Python, ha ha

Code
Diff
  • average=lambda t:[*map(__import__('numpy').average,zip(*t))]
    • average=lambda t:[*map(__import__('statistics').mean,zip(*t))]
    • average=lambda t:[*map(__import__('numpy').average,zip(*t))]