Re: making a anagram search on a wordlist
From: Larry Serflaten (serflaten_at_usinternet.com)
Date: 06/18/04
- Next message: Robert Chafer: "Re: Passing a value from one form to another"
- Previous message: Al Reid: "Re: Need to detect Null value in DB?"
- In reply to: Wilhil: "making a anagram search on a wordlist"
- Next in thread: J French: "Re: making a anagram search on a wordlist"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 18 Jun 2004 11:14:51 -0500
"Wilhil" <Wilhil@discussions.microsoft.com> wrote
> Hi
>
> basically I am trying to make a game where it generates out of random 9 characters. You have to make a word as quickly as
possible, It successfully looks up the word in the list, but I want it after I have done this to show me the best possible
combination.
How are you looking up the words in your list? I would think you need to build your
list such that it can support both types of lookup you want, namely 'exists' and 'best
match'.
How you do that depends on how much work you want to spend doing it....
Since your game uses combinations of letters, you might group your list by
the words that fit a certain combination. Here is a simple example, not fully
developed, (mutli letters not accounted for, etc,) but it may give you some
ideas...
HTH
LFS
Option Explicit
Private Type ListItem
hash As Long
List As String
End Type
Private WordList() As ListItem
Private Sub Form_Load()
ReDim WordList(2)
' Build list
WordList(0).hash = GetHash("apt")
WordList(0).List = ",apt,pat,tap,"
WordList(1).hash = GetHash("bat")
WordList(1).List = ",bat,tab,"
WordList(2).hash = GetHash("rat")
WordList(2).List = ",art,rat,tar,"
' Find Word
Debug.Print "BART="; WordExists("bart")
Debug.Print "ART="; WordExists("art")
' Show others
Debug.Print "Words for A B & T = "; FindMatch("abt")
End Sub
Private Function FindMatch(ByVal letters As String) As String
Dim hash As Long
Dim i As Long
hash = GetHash(letters)
For i = 0 To UBound(WordList)
If WordList(i).hash = hash Then
FindMatch = WordList(i).List
Exit Function
End If
Next
End Function
Private Function WordExists(ByVal word As String) As Boolean
Dim hash As Long
Dim i As Long
hash = GetHash(word)
word = "," & LCase$(word) & ","
For i = 0 To UBound(WordList)
If WordList(i).hash = hash Then
WordExists = InStr(WordList(i).List, word)
Exit Function
End If
Next
End Function
Private Function GetHash(ByVal word As String) As Long
Dim bit
word = LCase$(word)
For bit = 1 To Len(word)
GetHash = GetHash Or (2 ^ (Asc(word) - 97))
word = Mid$(word, 2)
Next
End Function
- Next message: Robert Chafer: "Re: Passing a value from one form to another"
- Previous message: Al Reid: "Re: Need to detect Null value in DB?"
- In reply to: Wilhil: "making a anagram search on a wordlist"
- Next in thread: J French: "Re: making a anagram search on a wordlist"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|