100 lines
2.7 KiB
Plaintext
100 lines
2.7 KiB
Plaintext
#include "file.bi"
|
|
|
|
Function String_Split(s_in As String,chars As String,result() As String) As Long
|
|
Dim As Long ctr,ctr2,k,n,LC=Len(chars)
|
|
Dim As boolean tally(Len(s_in))
|
|
#macro check_instring()
|
|
n=0
|
|
While n<Lc
|
|
If chars[n]=s_in[k] Then
|
|
tally(k)=true
|
|
If (ctr2-1) Then ctr+=1
|
|
ctr2=0
|
|
Exit While
|
|
End If
|
|
n+=1
|
|
Wend
|
|
#endmacro
|
|
|
|
#macro split()
|
|
If tally(k) Then
|
|
If (ctr2-1) Then ctr+=1:result(ctr)=Mid(s_in,k+2-ctr2,ctr2-1)
|
|
ctr2=0
|
|
End If
|
|
#endmacro
|
|
'================== LOOP TWICE =======================
|
|
For k =0 To Len(s_in)-1
|
|
ctr2+=1:check_instring()
|
|
Next k
|
|
if ctr=0 then
|
|
if len(s_in) andalso instr(chars,chr(s_in[0])) then ctr=1':beep
|
|
end if
|
|
If ctr Then Redim result(1 To ctr): ctr=0:ctr2=0 Else Return 0
|
|
For k =0 To Len(s_in)-1
|
|
ctr2+=1:split()
|
|
Next k
|
|
'===================== Last one ========================
|
|
If ctr2>0 Then
|
|
Redim Preserve result(1 To ctr+1)
|
|
result(ctr+1)=Mid(s_in,k+1-ctr2,ctr2)
|
|
End If
|
|
|
|
Return Ubound(result)
|
|
End Function
|
|
|
|
Function loadfile(file As String) As String
|
|
If Fileexists(file)=0 Then Print file;" not found":Sleep:End
|
|
Dim As Long f=Freefile
|
|
Open file For Binary Access Read As #f
|
|
Dim As String text
|
|
If Lof(f) > 0 Then
|
|
text = String(Lof(f), 0)
|
|
Get #f, , text
|
|
End If
|
|
Close #f
|
|
Return text
|
|
End Function
|
|
|
|
Function tally(SomeString As String,PartString As String) As Long
|
|
Dim As Long LenP=Len(PartString),count
|
|
Dim As Long position=Instr(SomeString,PartString)
|
|
If position=0 Then Return 0
|
|
While position>0
|
|
count+=1
|
|
position=Instr(position+LenP,SomeString,PartString)
|
|
Wend
|
|
Return count
|
|
End Function
|
|
|
|
Sub show(g As String,file As String,byref matches as long,minsize as long,mustdo as string)
|
|
Redim As String s()
|
|
Var L=lcase(loadfile(file))
|
|
g=lcase(g)
|
|
string_split(L,Chr(10),s())
|
|
For m As Long=minsize To len(g)
|
|
For n As Long=Lbound(s) To Ubound(s)
|
|
If Len(s(n))=m Then
|
|
For k As Long=0 To m-1
|
|
If Instr(g,Chr(s(n)[k]))=0 Then Goto lbl
|
|
Next k
|
|
If Instr(s(n),mustdo) Then
|
|
For j As Long=0 To Len(s(n))-1
|
|
If tally(s(n),Chr(s(n)[j]))>tally(g,Chr(s(n)[j])) Then Goto lbl
|
|
Next j
|
|
Print s(n)
|
|
matches+=1
|
|
End If
|
|
End If
|
|
lbl:
|
|
Next n
|
|
Next m
|
|
End Sub
|
|
|
|
dim as long matches
|
|
dim as double t=timer
|
|
show("ndeokgelw","unixdict.txt",matches,3,"k")
|
|
print
|
|
print "Overall time taken ";timer-t;" seconds"
|
|
print matches;" matches"
|
|
Sleep
|