! goodnight :) IN: factor-finder USING: ui.tools.search io.encodings.utf8 regexp splitting grouping fry sets ; : count-seq ( seq -- seq' ) dup '[ _ swap '[ _ = ] count ] map ; : count-dups ( seq -- seq ) dup count-seq zip prune >array ; : just-2+ ( seq -- seq ) [ dup second 2 < [ drop f ] when ] map harvest ; : sort-by-count ( seq -- seq ) [ [ second ] bi@ <=> ] sort reverse ; : read-as-one-string ( seq -- str ) [ utf8 file-contents ] map " " join ; : consistent-space ( str -- str ) "[\n|\r|\t|\s\s]" " " re-replace ; : split-to-words ( str -- seq ) " " split harvest ; : (prepare-clumps) ( n -- seq ) [ length >array ] dip short head [ 1+ ] map ; : make-words-groups ( count-array words -- groups ) [ swap clump ] curry map ; : words-to-phrases ( seq -- seq ) [ [ " " join ] map ] map ; : run-factor-finder ( -- ) all-source-files 30 short head read-as-one-string consistent-space split-to-words [ 10 (prepare-clumps) ] keep make-words-groups words-to-phrases [ count-dups ] map [ just-2+ ] map sort-by-count ;