home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine 1996 / ARCHIVE_96.iso / discs / mag_discs / volume_3 / issue10 / pipeline / SKIRROW / LETTER < prev    next >
Text File  |  1990-05-19  |  4KB  |  145 lines

  1. %OP%JUY
  2. %OP%DFT
  3. %OP%TM2
  4. %OP%BM4
  5. %OP%LM6
  6. %CO:A,12,72%
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15. Mr Gerald Fitton
  16. Abacus Training
  17. 29 Okus Grove
  18. Upper Stratton
  19. SWINDON
  20. Wilts
  21. SN2 6QA
  22.  
  23.  
  24. Dear Gerald,
  25.  
  26. %JR%In reply to your letter about the anagram competition, no I didn't use 
  27. Pipedream macros to find the anagrams, but here is the solution:
  28.  
  29. 1.  Dump the pipedream dictionary to a file called DumpedFile.
  30.  
  31. %JR%2.  Run the following program to sort the letters in each word into 
  32. alphabetical order:
  33.  
  34.     5 REM  >Champ
  35.    10 in%PC%=OPENIN"Dumpedfile"
  36.    20 out%PC%=OPENOUT"Words"
  37.    22 N%PC%=0
  38.    25 REPEAT
  39.    30   line$=GET$#in%PC%
  40.    32   in$=line$
  41.    35   out$=""
  42.    40   FOR C%PC%=ASC"a" TO ASC"z"
  43.    45     C$=CHR$C%PC%
  44.    50     I%PC%=INSTR(line$,C$)
  45.    60     IF I%PC%>0 THEN out$=out$+C$:
  46.           line$=LEFT$(line$,I%PC%-1)+MID$(line$,I%PC%+1):
  47.           GOTO50
  48.    70   NEXT
  49.    85   N%PC%+=1:
  50.         IF N%PC%MOD100=0 PRINT;N%PC%;TAB(9);in$;TAB(30);out$
  51.    90   BPUT#out%PC%,out$
  52.   100 UNTIL EOF#in%PC%
  53.   110 CLOSE#in%PC%
  54.   120 CLOSE#out%PC%
  55.  
  56. %JR%This will change "sort", "rots" and "tors" to "orst" for example, so 
  57. %JR%all anagrams of a particular word will be converted to the same new 
  58. word with all of its letters in alphabetical order.
  59.  
  60.  
  61.  
  62. %JR%3.  Now find the word that occurs most often in the "words" file.  
  63. %JR%There are various Unix and GNU utilities to do this (usually called 
  64. %JR%freq) but the versions I have ran out of memory on my 2Mbyte machine.  
  65. %JR%If you have a 4Mbyte machine you should be able to load the words file 
  66. %JR%into Pipedream to sort it, but again Pipedream ran out of memory trying 
  67. %JR%to load a 900K file even though I had 1300K free after loading 
  68. %JR%Pipedream (presumably Pipedream maintains a lot of pointers and other 
  69. information for every line).
  70.  
  71. %JR%The solution if you have 2Mbytes (but not 1Mbyte) is to run the 
  72. following Basic program to sort the words:
  73.  
  74.    10 REM  >SORT
  75.    20 file$="Words"
  76.    30 F%PC%=OPENIN file$
  77.    40 ext%PC%=EXT#F%PC%
  78.    45 CLOSE#F%PC%
  79.    50 DIM array%PC% ext%PC%+10
  80.    55 PRINT"Loading words"
  81.    60 OSCLI "load "+file$+" "+STR$~array%PC%
  82.    70 DIM ptr%PC% 400000:REM  100,000 words, 4 byte pointer
  83.    80 wc%PC%=1:
  84.       !ptr%PC%=array%PC%
  85.    85 PRINT"Building word pointers and terminating with CR chars"
  86.    90 FOR I%PC%=0 TO ext%PC%-1
  87.   100   IF array%PC%?I%PC%=10 THEN array%PC%?I%PC%=13:
  88.         ptr%PC%!(wc%PC%<<2)=array%PC%+I%PC%+1:
  89.         wc%PC%+=1
  90.   110 NEXT
  91.   115 T%PC%=TIME:
  92.       PRINT"Calling OS HeapSort"
  93.   120 SYS "OS_HeapSort",wc%PC%,ptr%PC%,4
  94.   121 PRINT"Sort took ";(TIME-T%PC%)/100;" seconds"
  95.   125  
  96.   126 out%PC%=OPENOUT"out"
  97.   130 FOR I%PC%=0 TO wc%PC%-1
  98.   140   add%PC%=ptr%PC%!(I%PC%<<2)
  99.   150   BPUT#out%PC%,$add%PC%
  100.   160 NEXT
  101.   180 CLOSE#out%PC%
  102.  
  103. %JR%This takes about 40 seconds to sort the words and save them in the file 
  104. "out".
  105.  
  106. %JR%4.  Now run the following program to find which words have a frequency 
  107. of 5 or more:
  108.  
  109.    10 REM >Count
  110.    15 freq%PC%=5
  111.    20 in%PC%=OPENIN"OUT"
  112.    26 last$=""
  113.    27 count%PC%=0
  114.    30 REPEAT
  115.    40   word$=GET$#in%PC%
  116.    50   IF word$=last$ THEN
  117.    60     count%PC%+=1
  118.    70     ELSE
  119.    80     IF count%PC%>=freq%PC% PRINTcount%PC%;CHR$9;last$
  120.    90     last$=word$:
  121.           count%PC%=1
  122.   100   ENDIF
  123.   110    
  124.   120 UNTIL EOF#in%PC%
  125.   130 CLOSE#in%PC%
  126.  
  127. %JR%Note that the words this program prints will normally be rubbish words 
  128. %JR%with their letters in alphabetical order.  It is usually easy to see 
  129. %JR%at least one anagram of the word (since they all have plenty) but if 
  130. %JR%you can't see it, just type the word into Pipedream's anagram search 
  131. and it will list them all.
  132.  
  133. Yours sincerely,
  134.  
  135.  
  136.  
  137. Paul M Skirrow
  138. %CO:B,12,60%%CO:C,12,48%%CO:D,12,36%%CO:E,12,24%9 Randwell Close
  139. IPSWICH
  140. IP4 5ES
  141.  
  142. Tel. 0473 728943
  143.  
  144. 19 May 1990
  145. %CO:F,12,12%