Word frequency: Difference between revisions
Content added Content deleted
m (→version 1: fixed program to handle an empty file or a file that has less than TOP words in it.) |
m (→version 1: elided a conditional test from a DO loop (by incorporating it into an UNTIL clause).) |
||
Line 261: | Line 261: | ||
say right('════',40) " " center('══════',6) "═══════" /* " a title separator.*/ |
say right('════',40) " " center('══════',6) "═══════" /* " a title separator.*/ |
||
do tops=1 by |
do tops=1 by 0 until otops==tops|tops>top /*process enough words to satisfy TOP.*/ |
||
tl=; |
tl=; mc=0; otops=tops /*initialize (possibly) a list of words*/ |
||
do n=1 for c; |
do n=1 for c; z=!.n; count=@.z /*process the list of words in the file*/ |
||
if count<1 then iterate /*Is count too small? Then ignore it.*/ |
if count<1 then iterate /*Is count too small? Then ignore it.*/ |
||
z=!.n /*get the name of the capitalized word.*/ |
z=!.n /*get the name of the capitalized word.*/ |
||
Line 279: | Line 279: | ||
end /*d*/ |
end /*d*/ |
||
tops=tops + words(tl) /*correctly handle the tied rankings. */ |
tops=tops + words(tl) /*correctly handle the tied rankings. */ |
||
if tops==otops then leave /*check case of empty/near-empty file. */ |
|||
end /*tops*/ /*stick a fork in it, we're all done. */</lang> |
end /*tops*/ /*stick a fork in it, we're all done. */</lang> |
||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |