Wait, it could probably be done with one pass through dictionary!
Just check each word to see if it has same letters as in the starting 9.
That algo might be same as bulls and cows (but only checking cows), except you can quit word as soon as there is no matching letter.
I am spending some time to speed up the search algorithm, so any additional ideas will be gratefully accepted.
This is my first program created with InForm. Firstly, I must reiterate members' comments on what a superb achievement is Fellippe's work in creating InForm. I have previously attempted to code in Microsoft's Visual Basic 6 (just about usable with no graphics available) and then their Visual Studio (completely unworkable). Fellippe has achieved everything that we should have desired from the Microsoft stuff with much easier usage and integrated into all that we wish to do in QB64. Hats off again to Fellippe.
The program provides all the solutions to a particular kind of puzzle (Trackword) which appears in a specialist magazine. Many years ago, I originally created a program for this in QuickBasic 2, and I have used this as a basis for learning to use InForm. InForm is so user-friendly that there was only a little work needed to convert from the original text-only program. In fact, the programming difficulty and interest was in the original work in creating the algorithm which finds all the solutions (and only those which are valid). Looking at the code now, it is quite difficult to work out how the algorithm works exactly. I must have been brighter all those years ago.
Should you be interested to run this specialist program, you will need to download the pdf. The solving routine needs tens of thousands of computational cycles and needs a modern fast machine. A slower machine will give a noticeable pause before answers are displayed. I should have programmed a progress bar, but I thought that this little starter project did not justify it.
Richard
The puzzle is specific in that the word has to snake through the grid, so letter order is specific. I am spending some time to speed up the search algorithm, so any additional ideas will be gratefully accepted. The computing time time taken up forming all the 10,256 allowed letter combinations, not so much checking the dictionary.
QuoteThe puzzle is specific in that the word has to snake through the grid, so letter order is specific. I am spending some time to speed up the search algorithm, so any additional ideas will be gratefully accepted. The computing time time taken up forming all the 10,256 allowed letter combinations, not so much checking the dictionary.
Hi Qwerkey,
I have worked out a 2 part system:
Part 1 builds a one time only, Master Snakes.txt file, that contains the 10256 letter snakes that can be formed on the 3x3 grid.
The snakes are listed as strings of square numbers. This is done once for all time, no need to do again.
Part 2:
Loads the snake patterns, the dictionary words and gets down to business by translating the square numbers to letters in the given word grid or just a 9 letter word string. With the word formed it checks the word list with binary search and stores all matches in array that is sorted and then displays and recounts only unique words.
You might like to see the little recursive gem that is only about a dozen lines called "build2" that gets all snake patterns for each square of grid, the heart of the whole thing.
If you wanted to make it more portable, you'd need to include 4 extra files in your zip, so that one wanting to run your program but not interested in the full InForm package could still do so:
One last thing I forgot to ask: Did you download the zip package for InForm or did you use the installer?
Does QB64 Team have another meaning?
Does QB64 Team have another meaning?
Well, kind of (https://twitter.com/qb64team). Luke, STxAxTIC and I maintain qb64.org under that name, so I guess that's what you meant after all?
Maybe "Team QB64"? ;-))
Odin wanted to show from the start that post racing would be frowned upon
WIDTH 80, 43
DIM parray(0 TO 8) AS LONG
FOR i = 0 TO UBOUND(parray)
parray(i) = i
NEXT
PRINT
PRINT
PRINT "permutations"
Permute parray(), 0, UBOUND(parray), np
DO
x$ = INKEY$
LOOP UNTIL x$ > ""
SYSTEM
SUB DisplayResults (PArray() AS LONG, start, finish, np AS DOUBLE)
DIM i AS LONG
PRINT USING "#,###,###,###,###"; np;
FOR i = LBOUND(parray) TO UBOUND(parray)
PRINT PArray(i);
NEXT
PRINT
END SUB
SUB Rotate (parray() AS LONG, Start AS LONG, finish AS LONG)
DIM ts AS LONG
ts = parray(Start)
FOR i = Start TO finish - 1
SWAP parray(i), parray(i + 1)
NEXT
parray(finish) = ts
END SUB
SUB Permute (parray() AS LONG, start AS LONG, finish AS LONG, np AS DOUBLE)
np = np + 1
DisplayResults parray(), LBOUND(parray), UBOUND(parray), np
IF start < finish THEN
DIM i AS LONG
DIM j AS LONG
FOR i = finish - 1 TO start STEP -1
FOR j = i + 1 TO finish
SWAP parray(i), parray(j)
Permute parray(), i + 1, finish, np
NEXT
Rotate parray(), i, finish
NEXT
END IF
END SUB