s" /usr/share/dict/words" r/o open-file throw value dict-words dict-words file-size throw constant dict-size dict-size 1+ allocate throw value dict-data dict-data dict-size dict-words read-file throw drop 0 dict-data dict-size + c! ( null terminate ) : upper ( ch -- ch) 95 and ; : upper*s ( a n -- ) 0 do dup c@ upper over c! 1+ loop drop ; dict-data dict-size upper*s : next-word ( a -- a ) begin 1+ dup c@ nl = until 1+ ; : each-step ( a -- a' a n ) dup next-word swap over over - 1- ; : each{ postpone begin postpone dup postpone c@ postpone while postpone each-step ; immediate : }each postpone repeat postpone drop ; immediate : letter? ( ch -- f ) dup [char] A >= swap [char] Z <= and ; : letters? ( a n ) -1 swap 0 do >r dup c@ letter? >r 1+ r> r> and loop nip ; : wordl? ( a n -- f ) 5 = if 5 letters? else drop 0 then ; 0 value wordls# create wordls 10000 cells allot : init-wordls dict-data each{ 2dup wordl? if drop wordls# cells wordls + ! 1 +to wordls# else 2drop then }each ; init-wordls : score1 { a b } 0 5 0 do a i + c@ b i + c@ = 2* 2* - loop 5 0 do 5 0 do a i + c@ b j + c@ = - loop loop 5 0 do 5 0 do a i + c@ a j + c@ = + loop loop ; : score { a } 0 wordls# 0 do a i cells wordls + @ score1 + loop ; : run wordls# 0 do i cells wordls + @ score . i cells wordls + @ 5 type cr loop ; run bye sort -n -r | head -n 100 1792 TARES 1582 CARES 1282 BARES 1241 DARES 1097 PARES 1074 TALES 988 MARES 833 LANES 770 CANES 583 HARES 564 BALES 523 DALES 470 BANES 429 DANES 423 FARES 379 PALES 285 PANES 276 RATES 270 MALES 203 AIRES 176 MANES 112 WARES 6 CORES -135 HALES -183 GALES -257 BATES -257 BATES -294 BORES -298 DATES -442 PATES -442 OATES -445 ARIES -479 ROLES -479 PORES -537 LADES -551 MATES -588 MORES -596 TONES -606 WALES -606 WALES -647 TAMES -650 RACES -700 WANES -794 LAMES -806 CONES -820 LACES -882 TIRES -911 RAPES -934 TAPES -956 HATES -1004 GATES -1004 GATES -1012 BOLES -1033 RAGES -1041 GORES -1053 DOLES -1106 BONES -1116 FATES -1116 FATES -1144 CAPES -1153 FORES -1197 POLES -1197 POLES -1198 DAMES -1218 VALES -1266 CAGES -1291 PONES -1301 ALOES -1306 MOLES -1312 VANES -1368 PACES -1403 RAKES -1426 TAKES -1477 MACES -1530 TRIES -1533 COTES -1552 RAVES -1573 LAKES -1577 RILES -1599 HADES -1600 TILES -1636 CAKES -1652 NAMES -1679 BAYES -1686 MIRES -1694 TINES -1711 HOLES -1740 CRIES -1749 YATES -1751 PAGES -1759 FADES -1785 CAVES -1805 HONES -1841 LINES -1874 DOTES -1904 GAMES -1936 BAKES -1939 NAPES -1979 AIDES -2025 RAZES