### Author Topic: My First InForm Program - Trackword  (Read 26981 times)

0 Members and 1 Guest are viewing this topic.

#### bplus

• Global Moderator
• Forum Resident
• Posts: 8053
• b = b + ...
##### Re: My First InForm Program - Trackword
« Reply #45 on: August 11, 2018, 11:06:34 pm »
Here is a much more interesting screen full. 9 letter words that have 200 or more words snaked around the 3x3 grid.

Now I am wondering how many are anagrams of each other.
« Last Edit: August 12, 2018, 12:10:16 am by odin »

#### bplus

• Global Moderator
• Forum Resident
• Posts: 8053
• b = b + ...
##### Re: My First InForm Program - Trackword
« Reply #46 on: August 12, 2018, 01:19:44 am »
I was surprised, not many of the Trackword 200+ were anagrams of each other:
Code: QB64: [Select]
1. _TITLE "Trackword 200 Anagram Analysis"
2. CONST ww = 800
3. CONST wh = 600
4.
5. SCREEN _NEWIMAGE(ww, wh, 32)
6. _SCREENMOVE (1280 - ww) / 2 + 30, (760 - wh) / 2
7.
8. 'PRINT AnagramTF%("artss", "stars")      'yeah!
9. DIM w\$(70), a\$(70)
10. wTop = 0
11. OPEN "Trackword 200.txt" FOR INPUT AS #1
12.     wTop = wTop + 1
13.     INPUT #1, w\$(wTop)
14. FOR i = 1 TO wTop
15.     IF w\$(i) <> "" THEN
16.         ai = ai + 1
17.         a\$(ai) = w\$(i)
18.         FOR j = i + 1 TO wTop
19.             IF w\$(j) <> "" THEN
20.                 IF AnagramTF(w\$(i), w\$(j)) THEN
21.                     a\$(ai) = a\$(ai) + " " + w\$(j) 'move to i word group
22.                     w\$(j) = "" ' this word is used
23. 'show results
24. FOR i = 1 TO ai
25.     IF i > 33 THEN
26.         l = i - 33: m = 40
27.         l = i: m = 1
28.     LOCATE l, m: PRINT i; " "; a\$(i)
29.
30. FUNCTION AnagramTF% (w1\$, w2\$)
31.     'this only works for words 9 repeated letters or less
32.     IF LEN(w1\$) <> LEN(w2\$) THEN EXIT FUNCTION 'false
33.     'still here
34.     aw1\$ = STRING\$(26, "0")
35.     aw2\$ = aw1\$
36.     FOR i = 1 TO LEN(w1\$)
37.         c\$ = UCASE\$(MID\$(w1\$, i, 1))
38.         ac = ASC(c\$) - 64
39.         vc = VAL(MID\$(aw1\$, ac, 1))
40.         MID\$(aw1\$, ac, 1) = LTRIM\$(STR\$(vc + 1))
41.         c\$ = UCASE\$(MID\$(w2\$, i, 1))
42.         ac = ASC(c\$) - 64
43.         vc = VAL(MID\$(aw2\$, ac, 1))
44.         MID\$(aw2\$, ac, 1) = LTRIM\$(STR\$(vc + 1))
45.     IF aw1\$ = aw2\$ THEN AnagramTF% = -1
46.

EDIT: fix with Ltrim\$ the str\$ of values

Dang! missing last word.
EDIT 2: fixed
« Last Edit: August 12, 2018, 01:49:03 am by bplus »

#### Qwerkey

• Forum Resident
• Posts: 755
##### Re: My First InForm Program - Trackword
« Reply #47 on: August 12, 2018, 04:34:19 am »
bplus, you certainly seem to have found much interest in this little problem.  Thanks for your stimulating inputs.

Richard

#### Qwerkey

• Forum Resident
• Posts: 755
##### Re: My First InForm Program - Trackword
« Reply #48 on: August 12, 2018, 06:01:59 am »
Another interesting thing to investigate is whether an arrangement of letters gives more than one nine-letter solution.

If you use the following grid, you gey both CARTHORSE and ORCHESTRA (well-known anagrams of each other):
CAR
RHT
OSE

I think that I remmber Clive Doig (he who invented Trackword) setting a puzzle where there were three nine-letter anagrams.  Can there be more than one such solution?  I don't suppose that there can be more than three?

Richard

#### Qwerkey

• Forum Resident
• Posts: 755
##### Re: My First InForm Program - Trackword
« Reply #49 on: August 12, 2018, 06:54:50 am »
bplus, the following arrangements (and others) all give the same results:

CAR   OSE   CRO   ETR
RHT   RHT    AHS   SHA
OSE   CAR   RTE   ORC

Working out symmetry considerations is beyond me.  Can we reduce HalfABC further by symmetry considerations?  Can we reduce search time even more?

Richard

#### bplus

• Global Moderator
• Forum Resident
• Posts: 8053
• b = b + ...
##### Re: My First InForm Program - Trackword
« Reply #50 on: August 12, 2018, 09:27:09 am »
Hi Richard,

With the 3x3 grid, there were 3 types of square, the corner, the side, and the middle. The middle was unique but the corner and side had 3 equivalent rotations that likely could be "translated" number for number for the snake patterns and in same manner for the letter patterns. The snakes could be worked out with results from one corner, side and middle but snakes are one time shot. Doing the same with letter patterns would likely take longer to calculate and translate than just translating a snake pattern to a letter pattern, So is it worth it to reduce snake patterns but require and do the same amount of translations?

The reverse trick was quite clever, easiest to understand and use.

Have you any thought about 4x4 grids? Probably learn even fancier words. :D   If one bothers to check them out eg, wadsetter :)  Which reminds me, do I have an actual dictionary with word AND definition? Such would be a natural addition if you'd like to try Menus with InForm. Heck, it might even be educational, learn while playing... :)

PS a message box would be handy for a quick definition.

« Last Edit: August 12, 2018, 09:31:54 am by bplus »

#### Qwerkey

• Forum Resident
• Posts: 755
##### Re: My First InForm Program - Trackword
« Reply #51 on: August 13, 2018, 12:51:56 pm »
Good heavens, bplus!  I am startled to find that our little topic here has made it into the Top Ten posts by replies.  We have only 21 more suggestions each and then we get to No. 1!

Richard

#### bplus

• Global Moderator
• Forum Resident
• Posts: 8053
• b = b + ...
##### Re: My First InForm Program - Trackword
« Reply #52 on: August 13, 2018, 01:39:12 pm »
Oh rats!

You have me looking for, and then at, forum stats. Interesting...

Well as Fellippe has mentioned numbers don't exactly mean quality but as I said, quantity is one quality of many...

How does Odin have so many posts? I looked at a quality Odin's posts, only 2 pages not exactly 500+ ???

Append: OK so it doesn't look like a blatant inflation of replies, something more on topic and that I am curious about.

What do you all think of adding an additional capability to define words? To me, it is a most logical, practical, educational and maybe even fun extension of this application of InForm.
« Last Edit: August 13, 2018, 01:48:58 pm by bplus »

#### FellippeHeitor

• Guest
##### Re: My First InForm Program - Trackword
« Reply #53 on: August 13, 2018, 01:41:44 pm »
Odin wanted to show from the start that post racing would be frowned upon
« Last Edit: August 13, 2018, 01:48:05 pm by FellippeHeitor »

#### bplus

• Global Moderator
• Forum Resident
• Posts: 8053
• b = b + ...
##### Re: My First InForm Program - Trackword
« Reply #54 on: August 13, 2018, 02:12:41 pm »
Odin wanted to show from the start that post racing would be frowned upon

#### Qwerkey

• Forum Resident
• Posts: 755
##### Re: My First InForm Program - Trackword
« Reply #55 on: August 14, 2018, 01:19:07 pm »
User Manual replaced in first section (updated with finished program instructions).  Previous version plus temporary updated version here downloaded 125/39 times (this reply modified 16/02/2019).
« Last Edit: February 16, 2019, 11:09:22 am by Qwerkey »

#### codeguy

• Forum Regular
• Posts: 174
##### Re: My First InForm Program - Trackword
« Reply #56 on: September 04, 2018, 04:55:18 pm »
one more attack that may speed up your progress is to generate permutations of your letters in alphabetic order and then do a modified merge search. Since the permutations are in the same lexicographical order as Steve's word list, there is no need to do binary search with a sorted array. Here is the code for generating permutations in ascending order.
Code: [Select]
`WIDTH 80, 43DIM parray(0 TO 8) AS LONGFOR i = 0 TO UBOUND(parray)    parray(i) = iNEXTPRINTPRINTPRINT "permutations"Permute parray(), 0, UBOUND(parray), npDO    x\$ = INKEY\$LOOP UNTIL x\$ > ""SYSTEMSUB DisplayResults (PArray() AS LONG, start, finish, np AS DOUBLE)DIM i AS LONGPRINT USING "#,###,###,###,###"; np;FOR i = LBOUND(parray) TO UBOUND(parray)    PRINT PArray(i);NEXTPRINTEND SUBSUB Rotate (parray() AS LONG, Start AS LONG, finish AS LONG)DIM ts AS LONGts = parray(Start)FOR i = Start TO finish - 1    SWAP parray(i), parray(i + 1)NEXTparray(finish) = tsEND SUBSUB Permute (parray() AS LONG, start AS LONG, finish AS LONG, np AS DOUBLE)np = np + 1DisplayResults parray(), LBOUND(parray), UBOUND(parray), npIF 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    NEXTEND IFEND SUB`

Code: QB64: [Select]
1. '* essentially finds the intersection of 2 arrays
2. '* both arrays must be sorted exactly the same order.
3. SUB ModifiedMergeSearch (StevesWordList\$(), MyWordList\$())
4. a& = 0
5. b& = 0
6.     IF a& > UBOUND(StevesWordList\$) THEN
7.         IF b& > UBOUND(MyWordList\$) THEN
8.             IF StevesWordList\$(a&) > MyWordList\$(b&) THEN
9.                 b& = b& + 1
10.             ELSEIF StevesWordList\$(a&) < MyWordList\$(b&) THEN
11.                 a& = a& + 1
12.                 '* it's a word in both lists
14.                 a& = a& + 1
15.                 b& = b& + 1
16.

#### Qwerkey

• Forum Resident
• Posts: 755
##### Re: My First InForm Program - Trackword
« Reply #57 on: September 05, 2018, 06:44:14 am »
Hmm.  Thanks codeguy.  I'm knee-deep in another program at the moment, but then I'll try to give this some consideration.

Richard