Paste: josephus

Author: mrjbq7
Mode: factor
Date: Wed, 1 May 2013 16:02:19
Plain Text |
:: josephus ( n k -- m )
    2 n [a,b] 0 [ [ k + ] dip mod ] reduce 1 + ;

: josephus2 ( n -- m )
    dup log2 2^ - 2 * 1 + ;

Annotation: Suggestion

Author: Loryn Jenkins / mrjbq7
Mode: factor
Date: Wed, 1 May 2013 18:24:06
Plain Text |
:: josephus' ( n k -- m ) n [1,b] 0 [ [ k + ] dip mod ] reduce ;

: josephus2' ( n -- m )
    dup log2 2^ - 2 * ;
        
:: josephus ( n k -- m )
    n 2 = [ k josephus2' ] [ n k josephus' ] if ;

Annotation: Suggestion Amended

Author: Loryn Jenkins / mrjbq7
Mode: factor
Date: Wed, 1 May 2013 18:29:52
Plain Text |
:: josephus' ( n k -- m ) 
    n [1,b] 0 [ [ k + ] dip mod ] reduce ;

: josephus2' ( n -- m )
    dup log2 2^ - 2 * ;
        
:: josephus ( n k -- m )
    k 2 = [ n josephus2' ] [ n k josephus' ] if ;

Annotation: infix

Author: mrjbq7
Mode: factor
Date: Wed, 1 May 2013 18:42:51
Plain Text |
USE: infix

INFIX:: josephus2 ( n -- m )
    2*(n-2**log2(n)) ;

Annotation: python in factor!

Author: mrjbq7
Mode: factor
Date: Wed, 1 May 2013 19:00:55
Plain Text |
USE: infix
ALIAS: def INFIX::

def josephus2 ( n -- m )
    2*(n-2**log2(n)) ;

New Annotation

Summary:
Author:
Mode:
Body: