Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
64
Task/Anagrams/BBC-BASIC/anagrams.basic
Normal file
64
Task/Anagrams/BBC-BASIC/anagrams.basic
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
INSTALL @lib$+"SORTLIB"
|
||||
sort% = FN_sortinit(0,0)
|
||||
|
||||
REM Count number of words in dictionary:
|
||||
nwords% = 0
|
||||
dict% = OPENIN("unixdict.txt")
|
||||
WHILE NOT EOF#dict%
|
||||
word$ = GET$#dict%
|
||||
nwords% += 1
|
||||
ENDWHILE
|
||||
CLOSE #dict%
|
||||
|
||||
REM Create arrays big enough to contain the dictionary:
|
||||
DIM dict$(nwords%), sort$(nwords%)
|
||||
|
||||
REM Load the dictionary and sort the characters in the words:
|
||||
dict% = OPENIN("unixdict.txt")
|
||||
FOR word% = 1 TO nwords%
|
||||
word$ = GET$#dict%
|
||||
dict$(word%) = word$
|
||||
sort$(word%) = FNsortchars(word$)
|
||||
NEXT word%
|
||||
CLOSE #dict%
|
||||
|
||||
REM Sort arrays using the 'sorted character' words as a key:
|
||||
C% = nwords%
|
||||
CALL sort%, sort$(1), dict$(1)
|
||||
|
||||
REM Count the longest sets of anagrams:
|
||||
max% = 0
|
||||
set% = 1
|
||||
FOR word% = 1 TO nwords%-1
|
||||
IF sort$(word%) = sort$(word%+1) THEN
|
||||
set% += 1
|
||||
ELSE
|
||||
IF set% > max% THEN max% = set%
|
||||
set% = 1
|
||||
ENDIF
|
||||
NEXT word%
|
||||
|
||||
REM Output the results:
|
||||
set% = 1
|
||||
FOR word% = 1 TO nwords%-1
|
||||
IF sort$(word%) = sort$(word%+1) THEN
|
||||
set% += 1
|
||||
ELSE
|
||||
IF set% = max% THEN
|
||||
FOR anagram% = word%-max%+1 TO word%
|
||||
PRINT dict$(anagram%),;
|
||||
NEXT
|
||||
PRINT
|
||||
ENDIF
|
||||
set% = 1
|
||||
ENDIF
|
||||
NEXT word%
|
||||
END
|
||||
|
||||
DEF FNsortchars(word$)
|
||||
LOCAL C%, char&()
|
||||
DIM char&(LEN(word$))
|
||||
$$^char&(0) = word$
|
||||
C% = LEN(word$)
|
||||
CALL sort%, char&(0)
|
||||
= $$^char&(0)
|
||||
Loading…
Add table
Add a link
Reference in a new issue