Ad
string_lower(_, _).
function foo() {
  return bar();
}
USING: ;
IN: example

: foo ( -- x ) 4 ;

IN: math.margins

! Overriding math.margins definitions
: ± ( -- y ) 5 ;
USING: namespaces vocabs.loader prettyprint ;
IN: example

vocab-roots get .
Code
Diff
  • def foo(n):
        if n == 0:
            while True:
                yield 0
        else:
            for v in foo(n-1):
                yield v+1
    • USING: kernel math generators combinators.extras ;
    • IN: example
    • GEN: foo ( n -- gen )
    • [ [ 0 yield ] forever ]
    • [ 1 - foo [ [ next 1 + yield ] keep ] forever drop ] if-zero ;
    • def foo(n):
    • if n == 0:
    • while True:
    • yield 0
    • else:
    • for v in foo(n-1):
    • yield v+1

Builds a stack of depth generators, each incrementing a value starting at 0 by 1 before yielding. vals number of items are then generated. Expected time complexity should be O(depth * vals), however we find that depth = 10, vals = 1000 is very fast, depth = 100, vals = 100 is somewhat slow, and depth = 1000, vals = 10 is extremely slow (times out).

USING: kernel math generators combinators.extras ;
IN: example

GEN: foo ( n -- gen )
  [ [ 0 yield ] forever ]
  [ 1 - foo [ [ next 1 + yield ] keep ] forever drop ] if-zero ;

Simply loading sequences.extras adds ~5-6 seconds of runtime.

USING: sequences.extras ;
IN: example

: foo ( -- v ) 1 ;
USING: ;
IN: foo

: bla ( -- ) 3 ;
print("Solution code")
USING: kernel sequences qw ;
IN: foo

: x ( seq -- counts ) qw{ n e w s } [ [ = ] curry count ] with map ; inline

-1

Code
Diff
  • def f(s,p):s.c='YNeos'[(p=='')+sum(map(ord,p.lower()))%324>0::2]
    KumiteFoo=type('',(),{"__init__":f,"solution":lambda s:s.c})
    • def f(s,p):s.c='No'if(p=='')+sum(map(ord,p.lower()))%324else'Yes'
    • def f(s,p):s.c='YNeos'[(p=='')+sum(map(ord,p.lower()))%324>0::2]
    • KumiteFoo=type('',(),{"__init__":f,"solution":lambda s:s.c})
pattern1 = r"\d|\((?R)\)"
pattern2 = r"(.*)00(?1)"
Code
Diff
  • USING: kernel parser sequences quotations prettyprint fry ;
    QUALIFIED-WITH: tools.testest tt
    IN: testest.extras
    
    
    : wrap-it ( quot -- wrapped )
      '[ tt:it#{ _ dip tt:}# ] ;
      
    : wrap-describe ( quot -- wrapped )
      '[ tt:describe#{ _ dip tt:}# ] ;
    
    SYNTAX: it#{ \ tt:}# parse-until >quotation wrap-it append! ;
    SYNTAX: describe#{ \ tt:}# parse-until >quotation wrap-describe append! ;
    
    
    • USING: kernel parser sequences quotations prettyprint fry ;
    • QUALIFIED-WITH: tools.testest tt
    • IN: testest.extras
    • : wrap-it ( quot -- wrapped )
    • '[ tt:it#{ _ dip tt:}# ] ;
    • : wrap-describe ( quot -- wrapped )
    • '[ tt:describe#{ _ dip tt:}# ] ;
    • SYNTAX: it#{ \ tt:}# parse-until >quotation wrap-it suffix! \ call suffix! ;
    • SYNTAX: describe#{ \ tt:}# parse-until >quotation wrap-describe suffix! \ call suffix! ;
    • SYNTAX: it#{ \ tt:}# parse-until >quotation wrap-it append! ;
    • SYNTAX: describe#{ \ tt:}# parse-until >quotation wrap-describe append! ;
USING: kernel parser sequences quotations prettyprint fry ;
QUALIFIED-WITH: tools.testest tt
IN: testest.extras


: wrap-it ( quot -- wrapped )
  '[ tt:it#{ _ dip tt:}# ] ;
  
: wrap-describe ( quot -- wrapped )
  '[ tt:describe#{ _ dip tt:}# ] ;

SYNTAX: it#{ \ tt:}# parse-until >quotation wrap-it suffix! \ call suffix! ;
SYNTAX: describe#{ \ tt:}# parse-until >quotation wrap-describe suffix! \ call suffix! ;
Code
Diff
  • from time import sleep, time
    
    def addition(a, b):
        start = time()
        sleep(a)
        sleep(b)
        return int(time() - start)
    • def bit1(cin,a,b):
    • s=cin^a^b
    • cout=(a and b) or (cin and (a^b))
    • return cout,s
    • from time import sleep, time
    • def addition(a, b):
    • p=32
    • tape_a=[0]*p
    • tape_b=[0]*p
    • tape=[0]*p
    • a=bin(a)[2:]
    • a="".join(("0"*(p-len(a)),a))
    • b=bin(b)[2:]
    • b="".join(("0"*(p-len(b)),b))
    • for i in range(0,p):
    • if a[i]=="0":
    • pass
    • else:
    • tape_a[i]=1
    • for i in range(0,p):
    • if b[i]=="0":
    • pass
    • else:
    • tape_b[i]=1
    • tape_a=tape_a[::-1]
    • tape_b=tape_b[::-1]
    • c=0
    • for i in range(0,p):
    • c,tape[i]=bit1(c,tape_a[i],tape_b[i])
    • tape=tape[::-1]
    • return int("".join(map(lambda a:str(a),tape)),2)
    • start = time()
    • sleep(a)
    • sleep(b)
    • return int(time() - start)
Loading more items...