Paste: majority

Author: yac
Mode: factor
Date: Sun, 24 Jul 2011 09:25:00
Plain Text |
TUPLE: ctr e n ;
: <ctr> ( -- ctr ) f 0 ctr boa ;
: check ( ctr e -- ctr' )
    over n>> zero? [ >>e 1 >>n ] [
        over e>> = [ [ 1 + ] change-n ] [ [ 1 - ] change-n ] if
    ] if ;
: majority ( seq -- e/f )
   <ctr> [ check ] reduce e>> ;

New Annotation

Summary:
Author:
Mode:
Body: