! 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