Factor-notes:words

From Zen/-/ackers

Jump to: navigation, search

USING: kernel math sequences math.ranges ; IN: r

(cycle-length) ( len m -- n )
   dup 1 = [
       drop
   ] [
       dup even? [ 2/ ] [ 3 * 1+ ] if
       >r 1+ r> (cycle-length)
   ] if ;
cycle-length ( m -- n )
   1 swap (cycle-length) ;
max-cycle-length ( a b -- n )
   [a,b] [ cycle-length ] map supremum ;



Annotation: using unfold Annotation by: erg File type: factor Created: Fri, 29 Feb 2008 14:49:32

USING: kernel math sequences math.ranges ; IN: r

cycle-length ( m -- n )
   [  dup 1 > ]
   [ dup even? [ 2/ ] [ 3 * 1+ ] if dup ]
   [ ] unfold nip length 1+ ;
max-cycle-length ( a b -- n )
   [a,b] [ cycle-length ] map supremum ;

Annotation: while is better than unfold in this case Annotation by: erg File type: factor Created: Fri, 29 Feb 2008 14:49:32

USING: kernel math sequences math.ranges ; IN: r

cycle-length ( m -- n)
   1 swap [ dup 1 > ]
   [ dup even? [ 2/ ] [ 3 * 1+ ] if >r 1+ r> ]
   [ drop ] while ;
max-cycle-length ( a b -- n )
   [a,b] [ cycle-length ] map supremum ;
Personal tools