langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
61
Task/Anagrams/PureBasic/anagrams.purebasic
Normal file
61
Task/Anagrams/PureBasic/anagrams.purebasic
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
InitNetwork() ;
|
||||
OpenConsole()
|
||||
|
||||
Procedure.s sortWord(word$)
|
||||
len.i = Len(word$)
|
||||
Dim CharArray.s (len)
|
||||
|
||||
For n = 1 To len ; Transfering each single character
|
||||
CharArray(n) = Mid(word$, n, 1) ; of the word into an array.
|
||||
Next
|
||||
|
||||
SortArray(CharArray(),#PB_Sort_NoCase ) ; Sorting the array.
|
||||
|
||||
word$ =""
|
||||
For n = 1 To len ; Writing back each single
|
||||
word$ + CharArray(n) ; character of the array.
|
||||
Next
|
||||
|
||||
ProcedureReturn word$
|
||||
EndProcedure
|
||||
|
||||
|
||||
tmpdir$ = GetTemporaryDirectory()
|
||||
filename$ = tmpdir$ + "unixdict.txt"
|
||||
Structure ana
|
||||
isana.l
|
||||
anas.s
|
||||
EndStructure
|
||||
|
||||
NewMap anaMap.ana()
|
||||
|
||||
If ReceiveHTTPFile("http://www.puzzlers.org/pub/wordlists/unixdict.txt", filename$)
|
||||
If ReadFile(1, filename$)
|
||||
Repeat
|
||||
word$ = (ReadString(1)) ; Reading a word from a file.
|
||||
key$ = (sortWord(word$)) ; Sorting the word and storing in key$.
|
||||
|
||||
If FindMapElement(anaMap(), key$) ; Looking up if a word already had the same key$.
|
||||
|
||||
; if yes
|
||||
anaMap()\anas = anaMap()\anas+ ", " + word$ ; adding the word
|
||||
anaMap()\isana + 1
|
||||
Else
|
||||
; if no
|
||||
anaMap(key$)\anas = word$ ; applying a new record
|
||||
anaMap()\isana + 1
|
||||
EndIf
|
||||
Until Eof(1)
|
||||
CloseFile(1)
|
||||
DeleteFile(filename$)
|
||||
|
||||
;----- output -----
|
||||
ForEach anaMap()
|
||||
If anaMap()\isana >= 4 ; only emit what had 4 or more hits.
|
||||
PrintN(anaMap()\anas)
|
||||
EndIf
|
||||
Next
|
||||
|
||||
PrintN("Press any key"): Repeat: Until Inkey() <> ""
|
||||
EndIf
|
||||
EndIf
|
||||
Loading…
Add table
Add a link
Reference in a new issue