Paste: wp

Author: mrjbq7
Mode: factor
Date: Tue, 9 Dec 2008 17:52:08
Plain Text |
! Copyright (C) 2008 John Benediktsson
! See http://factorcode.org/license.txt for BSD license

USING: arrays assocs kernel io math math.parser namespaces 
prettyprint sequences splitting sorting ;

IN: wp

: split-words ( string -- seq ) 
    " " split [ length 0 > ] filter ;

: count-items ( assoc seq -- assoc' )
    [ swap [ [ 0 or 1+ ] change-at ] keep ] each ;

: print-item ( result -- ) 
    dup [ first ] [ second ] bi*
    [ write "   " write ] [ number>string print ] bi* ;

: sort-assoc ( assoc -- seq ) 
    [ 2array ] { } assoc>map sort-values reverse ;

H{ } clone [ split-words count-items ] each-line sort-assoc [ print-item ] each

Annotation: simpler

Author: mrjbq7
Mode: factor
Date: Tue, 9 Dec 2008 18:26:40
Plain Text |
! Copyright (C) 2008 John Benediktsson
! See http://factorcode.org/license.txt for BSD license

USING: arrays assocs kernel io math math.parser 
prettyprint sequences splitting sorting ;

IN: wp

: count-words ( assoc string -- assoc' )
    " " split harvest [ swap [ [ 0 or 1+ ] change-at ] keep ] each ;

: sort-assoc ( assoc -- seq ) 
    [ 2array ] { } assoc>map sort-values reverse ;

: print-results ( seq -- )
    [ first2 number>string "    " glue print ] each ;

H{ } clone [ count-words ] each-line sort-assoc print-results

Annotation: the "wp" website

Author: mrjbq7
Mode: text
Date: Tue, 9 Dec 2008 20:11:59
Plain Text |
http://ptrace.fefe.de/wp/

New Annotation

Summary:
Author:
Mode:
Body: