Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function IsWord%(test$)
#3
For example:

Code: (Select All)
Screen _NewImage(1024, 720, 32)
$Color:32

ReDim dict(0) As String
t1 = Timer(0.001)
LoadWordList "Scrabble WordList 2006.txt", dict()
t2 = Timer(0.001)

Print Using "#.##### seconds to load ###,### words."; t2 - t1, UBound(dict)
For i = 1 To 10
    Print dict(i),
Next
Print
For i = UBound(dict) - 10 To UBound(dict)
    Print dict(i),
Next
Print

'and just to showcase how quick arrays are, let's do a random search of the array from start to bottom
For i = 1 To 100 'let's look for 100 random words
    word$ = Chr$(65 + Rnd * 26) + Chr$(65 + Rnd * 26) + Chr$(65 + Rnd * 26)
    match = _FALSE
    For j = 1 To UBound(dict)
        Color Yellow
        If word$ = dict(j) Then Print "MATCH:"; word$,: match = _TRUE
        Color White
    Next
    If _Negate (match) Then Print "No match:"; word$,
Next

'note that this is doing nothing to binary search, nor is it exiting after finding a match, nor doing anything else to speed up the process
'this is simply testing the entire word array one by one looking for a match for our words.
'and it takes... no noticable time at all.

Sub LoadWordList (file$, WordList() As String) 'this sub loads a list of words for use later
    $Checking:Off
    Dim As String temp, t1
    Dim As Long count, p, p1
    ReDim WordList(250000) As String 'let's make a nice large array to told the words.
    '                                    I doubt any word list is going to have more than 250,000 words in it!
    If _FileExists(file$) Then 'then we have a found word list.  Let's load and parse it
        temp = _ReadFile$(file$)
        p = 1
        Do
            p1 = InStr(p, temp, Chr$(10)) 'look for a chr$(10) end of line marker
            If p1 = 0 Then p1 = InStr(p, temp, Chr$(13)) 'if no chr$(10) then look for a chr$(13) for odd files with it as the CRLF
            If p1 Then 'then we have a delimiter
                t1 = _Trim$(Mid$(temp, p, p1 - p))
                If Right$(t1, 1) = Chr$(13) Then t1 = Left$(t1, Len(t1) - 1) 'if CRLF then strip off chr$(13)
                If t1 <> "" Then 'don't add blank lines to the list
                    count = count + 1
                    WordList(count) = t1
                End If
                p = p1 + 1
            End If
        Loop Until p1 = 0
        If p < Len(temp) Then 'if there's no CRLF for the end of file, we want to last word here
            t1 = Mid$(temp$, p)
            If t1 <> "" Then 'again, don't add if it's a blank line
                count = count + 1
                WordList(count) = Mid$(temp, p)
            End If
        End If
    End If
    ReDim _Preserve WordList(count) As String
    $Checking:On
End Sub


Attached Files
.txt   Scrabble WordList 2006.txt (Size: 1.85 MB / Downloads: 1)
Reply


Messages In This Thread
Function IsWord%(test$) - by bplus - 02-25-2026, 08:58 PM
RE: Function IsWord%(test$) - by SMcNeill - 02-25-2026, 09:27 PM
RE: Function IsWord%(test$) - by SMcNeill - 02-25-2026, 10:16 PM
RE: Function IsWord%(test$) - by SMcNeill - 02-25-2026, 10:25 PM
RE: Function IsWord%(test$) - by bplus - 02-25-2026, 11:34 PM
RE: Function IsWord%(test$) - by mdijkens - 02-26-2026, 02:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Zeller's congruence pass 3: test day-of-week calculation algorythms for accuracy TDarcos 0 1,100 10-23-2024, 05:04 PM
Last Post: TDarcos
  Test sorting algorithms eoredson 3 972 05-04-2023, 09:38 PM
Last Post: eoredson
  Long Date Function AtomicSlaughter 2 974 05-24-2022, 08:22 PM
Last Post: bplus

Forum Jump:


Users browsing this thread: 1 Guest(s)