Author Topic: Word ladder - Rosetta Code  (Read 17671 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Word ladder - Rosetta Code
« on: September 03, 2021, 08:46:12 pm »
ref: http://rosettacode.org/wiki/Word_ladder

Oh this was a little more tricky!

Code: QB64: [Select]
  1. _Title "Word ladder - Rosetta Code" 'b+ start 2021-09-03 ref: http://rosettacode.org/wiki/Word_ladder
  2. Type connectType
  3.     connect As String
  4.     word As String
  5.  
  6. Dim Shared wordList$(2 To 7)
  7. LoadWords 'build the strings for each word length the split them for that length
  8. Print ladder$("boy", "man") '     quick
  9. Print ladder$("girl", "lady") '   this takes awhile
  10. Print ladder$("john", "jane") '   quick enough
  11. Print ladder$("alien", "drool") ' cool but takes a long long time!
  12. Print ladder$("child", "adult") ' and this takes awhile
  13. Print ladder$("play", "ball") '   goes quick
  14. Print ladder$("fun", "job") '     ditto
  15.  
  16. Sub LoadWords
  17.     Open "unixdict.txt" For Input As #1
  18.     While EOF(1) = 0
  19.         Input #1, wd$
  20.         If Len(wd$) > 1 And Len(wd$) < 8 Then
  21.             ok = -1
  22.             For m = 1 To Len(wd$)
  23.                 If Asc(wd$, m) < 97 Or Asc(wd$, m) > 122 Then ok = 0: Exit For
  24.             Next
  25.             If ok Then
  26.                 If wordList$(Len(wd$)) = "" Then wordList$(Len(wd$)) = wd$ Else wordList$(Len(wd$)) = wordList$(Len(wd$)) + " " + wd$
  27.             End If
  28.         End If
  29.     Wend
  30.     Close #1
  31.  
  32. Function ladder$ (w1$, w2$)
  33.     If Len(w1$) <> Len(w2$) Then ladder$ = "": Exit Function
  34.     ReDim TheList(1 To 1) As connectType, listPlace
  35.     ReDim wl$(1 To 1)
  36.     Split wordList$(Len(w1$)), " ", wl$()
  37.     connect$ = w1$
  38.  
  39.     newConnect:
  40.     'progress
  41.     'Print "Connect word is "; connect$; UBound(wl$); listPlace;
  42.     For i = 1 To UBound(wl$)
  43.         If oneChange%(connect$, wl$(i)) Then
  44.             If TheList(1).connect = "" Then
  45.                 TheList(1).connect = connect$
  46.                 TheList(1).word = wl$(i)
  47.             Else ' add to list only if word isn't a connect
  48.                 found = 0
  49.                 For j = 1 To UBound(theList)
  50.                     If wl$(i) = TheList(j).connect Then found = -1: Exit For
  51.                 Next
  52.                 If found = 0 Then
  53.                     cAppend TheList(), connect$, wl$(i)
  54.                 End If
  55.             End If
  56.             If wl$(i) = w2$ Then done = -1: Exit For
  57.         End If
  58.     Next
  59.     If done = 0 Then
  60.         listPlace = listPlace + 1
  61.         If listPlace > UBound(TheList) Then
  62.             ladder$ = "Could NOT connect " + w1$ + " to " + w2$
  63.         Else
  64.             connect$ = TheList(listPlace).word
  65.             GoTo newConnect
  66.         End If
  67.     Else
  68.         'should be able to backtrack our path?
  69.         ladder$ = "Could connect " + w1$ + " to " + w2$
  70.         target$ = w2$: trail$ = w2$
  71.         again:
  72.         For i = 1 To UBound(theList)
  73.             If TheList(i).word = target$ Then target$ = TheList(i).connect: trail$ = target$ + " > " + trail$: GoTo again
  74.         Next
  75.         ladder$ = ladder$ + Chr$(10) + trail$
  76.     End If
  77.  
  78. Sub Split (SplitMeString As String, delim As String, loadMeArray() As String)
  79.     Dim curpos As Long, arrpos As Long, LD As Long, dpos As Long 'fix use the Lbound the array already has
  80.     curpos = 1: arrpos = LBound(loadMeArray): LD = Len(delim)
  81.     dpos = InStr(curpos, SplitMeString, delim)
  82.     Do Until dpos = 0
  83.         loadMeArray(arrpos) = Mid$(SplitMeString, curpos, dpos - curpos)
  84.         arrpos = arrpos + 1
  85.         If arrpos > UBound(loadMeArray) Then ReDim _Preserve loadMeArray(LBound(loadMeArray) To UBound(loadMeArray) + 1000) As String
  86.         curpos = dpos + LD
  87.         dpos = InStr(curpos, SplitMeString, delim)
  88.     Loop
  89.     loadMeArray(arrpos) = Mid$(SplitMeString, curpos)
  90.     ReDim _Preserve loadMeArray(LBound(loadMeArray) To arrpos) As String 'get the ubound correct
  91.  
  92. Sub cAppend (arr() As connectType, cWrd$, w$)
  93.     ReDim _Preserve arr(LBound(arr) To UBound(arr) + 1) As connectType
  94.     arr(UBound(arr)).connect = cWrd$
  95.     arr(UBound(arr)).word = w$
  96.  
  97. Function oneChange% (last$, test$)
  98.     For i = 1 To Len(last$)
  99.         If Mid$(last$, i, 1) <> Mid$(test$, i, 1) Then strike = strike + 1
  100.     Next
  101.     If strike = 1 Then oneChange% = -1
  102.  
  103.  
  104.  

Same unixdict.txt for words attached and screen shot of output.
 
Word ladder output.PNG


All original in Basic!
* unixdict.txt (Filesize: 201.57 KB, Downloads: 246)
« Last Edit: September 03, 2021, 08:49:12 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Word ladder - Rosetta Code
« Reply #1 on: September 05, 2021, 11:40:48 am »
There is an interesting structure here, like directories it's all down hill from one word to another for shortest path but! that can be reversed. I should try this tracking the whole path in the connect string of the ConnectType.
« Last Edit: September 05, 2021, 11:41:59 am by bplus »

Offline david_uwi

  • Newbie
  • Posts: 71
    • View Profile
Re: Word ladder - Rosetta Code
« Reply #2 on: September 07, 2021, 01:48:19 pm »
Interesting challenge. I haven't quite worked out a strategy yet, but I was tending towards a string to log the movement of the letters - as you seem to be suggesting. I notice you use quite a small dictionary which still contains a number of dubious words aaas, aaa, aarhus - just a few at the beginning. Are you just being lucky or do you filter out these wack words.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Word ladder - Rosetta Code
« Reply #3 on: September 07, 2021, 02:00:40 pm »
Hi @david_uwi

Yeah that dictionary is standard given for all Rosetta Code word challenges. The more words the better, goof ball or not, when trying to go from one word to another one letter change at a time. I do filter out digits and other words that don't have standard 26 English letters of alphabet. BTW I learned from Wordiff Challenge that the dictionary does not have "has"!? There are more common ones missing.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Word ladder - Rosetta Code
« Reply #4 on: September 07, 2021, 02:15:08 pm »
Noticed it also doesn’t show multiple shortest paths.

For example, boy to man:

boy - bay - ban - man
boy - bay - may - man
boy - moy - may - man
boy - bon - ban - man
boy - bon - mon - man

Each of those are valid 4 word paths, and there’s probably more.  Those are just the ones I could come up with quickly off the top of my head.  ;D
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Word ladder - Rosetta Code
« Reply #5 on: September 07, 2021, 03:27:13 pm »
Noticed it also doesn’t show multiple shortest paths.

For example, boy to man:

boy - bay - ban - man
boy - bay - may - man
boy - moy - may - man
boy - bon - ban - man
boy - bon - mon - man

Each of those are valid 4 word paths, and there’s probably more.  Those are just the ones I could come up with quickly off the top of my head.  ;D

Some of the PL's at RC were showing multiple paths of equal length but I say if equal in length then go alphabetic to settle differences, there can be only one shortest path ;-))
(I say that because that was the way they were coming up.)

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Word ladder - Rosetta Code
« Reply #6 on: September 07, 2021, 06:10:37 pm »
I checked out 'Rosetta Code', as per the above link, and noticed the absence of any version of Basic... This may be a discussion for another time, but I am eager to know, just how was the 'Word Ladder' converted to Basic? Someone must have a knowledge of any of those languages AND an understanding of QB64... Hmm... Did I just answer my own question? Never mind. At least someone knows how... lol
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Word ladder - Rosetta Code
« Reply #7 on: September 07, 2021, 11:06:46 pm »
Quote
This may be a discussion for another time, but I am eager to know, just how was the 'Word Ladder' converted to Basic?

Hi @johnno56
Word Ladder wasn't converted, as I said "All original Basic!" Many of those languages I dont have a clue!
I do like to peek at FreeBASIC or BBC maybe or some other Basics even Python after I try my ideas out.


I have worked out an alternate version v2 that doesn't need to backtrack at the end to find the whole path. It tracks the path along with the connect (the last word in path before w2$), so when it finds the target word it's done you just pull the path from the last item loaded into TheList(). Too bad it runs 3 mins longer than the original version! I guess maintaining the path for every word in the list was very costly in processing time.

Here is what not to do to try to beat the first version in time:
Code: QB64: [Select]
  1. _Title "Word ladder v2 - Rosetta Code" 'b+ start 2021-09-03 ref: http://rosettacode.org/wiki/Word_ladder
  2. ' v2 2021-09-07 try building the whole path back to start word in the connect part of Connect Type
  3. ' so far it does the short ones ok but hangs on longer ones (fixed)
  4. ' adding path to connectType to avoid having to isolate last words in path
  5. ' OK it works now for timed test to see if it is better than 1 version, hell no!
  6.  
  7. Type connectType
  8.     path As String
  9.     connect As String
  10.     word As String
  11.  
  12. Dim Shared wordList$(2 To 7)
  13. start! = Timer(.001)
  14. LoadWords 'build the strings for each word length the split them for that length
  15. Print ladder$("boy", "man") '     quick
  16. Print ladder$("girl", "lady") '   this takes awhile
  17. Print ladder$("john", "jane") '   quick enough
  18. Print ladder$("alien", "drool") ' cool but takes a long long time!
  19. Print ladder$("child", "adult") ' and this takes awhile
  20. Print ladder$("play", "ball") '   goes quick
  21. Print ladder$("fun", "job") '     ditto
  22. Print Timer(.001) - start!
  23.  
  24. Sub LoadWords
  25.     Open "unixdict.txt" For Input As #1
  26.     While EOF(1) = 0
  27.         Input #1, wd$
  28.         If Len(wd$) > 1 And Len(wd$) < 8 Then
  29.             ok = -1
  30.             For m = 1 To Len(wd$)
  31.                 If Asc(wd$, m) < 97 Or Asc(wd$, m) > 122 Then ok = 0: Exit For
  32.             Next
  33.             If ok Then
  34.                 If wordList$(Len(wd$)) = "" Then wordList$(Len(wd$)) = wd$ Else wordList$(Len(wd$)) = wordList$(Len(wd$)) + " " + wd$
  35.             End If
  36.         End If
  37.     Wend
  38.     Close #1
  39.  
  40. Function ladder$ (w1$, w2$)
  41.     If Len(w1$) <> Len(w2$) Then ladder$ = "": Exit Function
  42.     ReDim TheList(1 To 1) As connectType, listPlace
  43.     ReDim wl$(1 To 1)
  44.     Split wordList$(Len(w1$)), " ", wl$()
  45.     PathedConnect$ = ">>" + w1$ ' double >> signals root
  46.     Connect$ = w1$
  47.     newConnect:
  48.     'progress
  49.     'Print "Connect word is "; connect$; UBound(wl$); listPlace;
  50.     For i = 1 To UBound(wl$)
  51.         If oneChange%(Connect$, wl$(i)) Then
  52.             If TheList(1).connect = "" Then
  53.                 TheList(1).path = PathedConnect$
  54.                 TheList(1).connect = Connect$
  55.                 TheList(1).word = wl$(i)
  56.             Else ' add to list only if word isn't a connect
  57.                 found = 0
  58.                 For j = 1 To UBound(theList) ' see if word is already on our list
  59.                     If wl$(i) = TheList(j).connect Then found = -1: Exit For
  60.                 Next
  61.                 If found = 0 Then ' not in List so add it to list
  62.                     cAppend TheList(), PathedConnect$, Connect$, wl$(i)
  63.                 End If
  64.             End If
  65.             If wl$(i) = w2$ Then done = -1: Exit For
  66.         End If
  67.     Next
  68.     If done = 0 Then
  69.         listPlace = listPlace + 1
  70.         If listPlace > UBound(TheList) Then
  71.             ladder$ = "Could NOT connect " + w1$ + " to " + w2$
  72.         Else
  73.             PathedConnect$ = TheList(listPlace).path + ">" + TheList(listPlace).word
  74.             Connect$ = TheList(listPlace).word
  75.             GoTo newConnect
  76.         End If
  77.     Else
  78.         'the very last item added to list had 2nd word connected to it, the .path has the first path (shortest) that got to it.
  79.         ladder$ = "Could connect " + w1$ + " to " + w2$ + Chr$(10) + TheList(UBound(thelist)).path + ">" + w2$
  80.     End If
  81.  
  82. Sub Split (SplitMeString As String, delim As String, loadMeArray() As String)
  83.     Dim curpos As Long, arrpos As Long, LD As Long, dpos As Long 'fix use the Lbound the array already has
  84.     curpos = 1: arrpos = LBound(loadMeArray): LD = Len(delim)
  85.     dpos = InStr(curpos, SplitMeString, delim)
  86.     Do Until dpos = 0
  87.         loadMeArray(arrpos) = Mid$(SplitMeString, curpos, dpos - curpos)
  88.         arrpos = arrpos + 1
  89.         If arrpos > UBound(loadMeArray) Then ReDim _Preserve loadMeArray(LBound(loadMeArray) To UBound(loadMeArray) + 1000) As String
  90.         curpos = dpos + LD
  91.         dpos = InStr(curpos, SplitMeString, delim)
  92.     Loop
  93.     loadMeArray(arrpos) = Mid$(SplitMeString, curpos)
  94.     ReDim _Preserve loadMeArray(LBound(loadMeArray) To arrpos) As String 'get the ubound correct
  95.  
  96. Sub cAppend (arr() As connectType, path$, cWrd$, w$)
  97.     ReDim _Preserve arr(LBound(arr) To UBound(arr) + 1) As connectType
  98.     arr(UBound(arr)).path = path$
  99.     arr(UBound(arr)).connect = cWrd$
  100.     arr(UBound(arr)).word = w$
  101.  
  102. Function oneChange% (last$, test$)
  103.     For i = 1 To Len(last$)
  104.         If Mid$(last$, i, 1) <> Mid$(test$, i, 1) Then strike = strike + 1
  105.     Next
  106.     If strike = 1 Then oneChange% = -1
  107.  
  108. 'Function LastRightOf$ (source$, of$)   'abandoned to adding a path to ConnectType
  109. '    For i = Len(source$) To 1 Step -1
  110. '        If Mid$(source$, i, 1) = of$ Then LastRightOf$ = Mid$(source$, i + 1): Exit Function
  111. '    Next
  112. 'End Function
  113.  
  114.  
« Last Edit: September 07, 2021, 11:09:26 pm by bplus »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Word ladder - Rosetta Code
« Reply #8 on: September 08, 2021, 06:06:49 am »
I remember doing these in puzzle magazines. First word and Last word are shown but you could only make 3 changes by changing only one letter each turn. But the new word had to be a 'real' word. So much fun.

Ran the above... Could not connect child to adult and could not connect fun to job.
Ran for 496.0862...   Is that good? Do I get a prize? lol

Just had a weird thought... don't even think about it... The program uses a dictionary of 25k+ words.
Correct me if I'm wrong... The program looks like it is comparing words of equal length? Would it not make the search quicker if the dictionary was split up into files of equal word lengths? eg: if the first word was five characters long then only open the 5 character word file. Just a thought.

I now have my coffee and all the crazy ideas are abating....
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Word ladder - Rosetta Code
« Reply #9 on: September 08, 2021, 07:47:30 am »
Hi @johnno56

With first version my system ran code 403 and 416 secs, v2 ran 579 and 541 secs about 3 minutes difference.

You are not supposed to find a connect from child to adult but are supposed to connect fun to job and that goes fairly quick too.

Quote
Correct me if I'm wrong... The program looks like it is comparing words of equal length? Would it not make the search quicker if the dictionary was split up into files of equal word lengths? eg: if the first word was five characters long then only open the 5 character word file. Just a thought.

I did use that idea when loading the file, I loaded words of same length into very long strings. Then when Ladder sub gets 2 words to connect it checks their length, makes sure they are same and then splits the long string of words of that length into an array for connect words.

Just ran v2 again fun does connect to job ">>fun>bun>bon,bob,job total time 569 secs on my system.

What is bon? I can hear you asking.
According to Oxford Languages = a Japanese Buddhist festival held annually in August to honor the dead.

Dang just missed it.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Word ladder - Rosetta Code
« Reply #10 on: September 08, 2021, 09:01:26 am »
bon is also a type of bean, grass, and the name of a hindu based religion.

It’s also French for good, if my memory’s correct.  “Bon appetite.”
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline david_uwi

  • Newbie
  • Posts: 71
    • View Profile
Re: Word ladder - Rosetta Code
« Reply #11 on: September 08, 2021, 02:02:33 pm »
Well I've got something to work - it was tricky.
The number of words increases dramatically on each letter substitution - I'm sure that there is a lot of redundancy there.
Anyway fun --> job took 1.6 seconds. It found fun-bun-bon-bob-job and fun-bun-bub-bob-job and fun-fin-fib-fob-job (which I like the best).
I have two questions
How long did yours take from job to fun and how big was the word list on each step. For mine it was
13,117,1222,11092 (just to check I'm moving on the right path).

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Word ladder - Rosetta Code
« Reply #12 on: September 08, 2021, 03:23:25 pm »
OK I am running v3 a revision of the original, now has timed each ladder call and also shows the ubound of The List array used to store all the word connections.

While we wait... oh dang, had I put sleep at end then wouldn't have scrolled, do over... dang didn't help:
Quote
How long did yours take from job to fun and how big was the word list on each step. For mine it was
13,117,1222,11092 (just to check I'm moving on the right path).

@david_uwi
11092 seems high, I am running through what I have in TheList so I don't add a duplicate connect, only add unique connects to avoid duplicate efforts. 

OK the results are in for:
Code: QB64: [Select]
  1. _Title "Word ladder v3 - Rosetta Code" 'b+ start 2021-09-03 ref: http://rosettacode.org/wiki/Word_ladder
  2. ' 2021-09-08  v3 is just v1 (original) plus times and TheList uBound added to the report
  3.  
  4. Type connectType
  5.     connect As String
  6.     word As String
  7.  
  8. Dim Shared wordList$(2 To 7)
  9. start! = Timer(1)
  10. LoadWords 'build the strings for each word length the split them for that length
  11. Print ladder$("boy", "man") '     quick
  12. Print ladder$("girl", "lady") '   this takes awhile
  13. Print ladder$("john", "jane") '   quick enough
  14. Print ladder$("alien", "drool") ' cool but takes a long long time!
  15. Print ladder$("child", "adult") ' and this takes awhile
  16. Print ladder$("play", "ball") '   goes quick
  17. Print ladder$("fun", "job") '     ditto
  18. Print Timer(.001) - start!
  19.  
  20. Sub LoadWords
  21.     Open "unixdict.txt" For Input As #1
  22.     While EOF(1) = 0
  23.         Input #1, wd$
  24.         If Len(wd$) > 1 And Len(wd$) < 8 Then
  25.             ok = -1
  26.             For m = 1 To Len(wd$)
  27.                 If Asc(wd$, m) < 97 Or Asc(wd$, m) > 122 Then ok = 0: Exit For
  28.             Next
  29.             If ok Then
  30.                 If wordList$(Len(wd$)) = "" Then wordList$(Len(wd$)) = wd$ Else wordList$(Len(wd$)) = wordList$(Len(wd$)) + " " + wd$
  31.             End If
  32.         End If
  33.     Wend
  34.     Close #1
  35.  
  36. Function ladder$ (w1$, w2$)
  37.     If Len(w1$) <> Len(w2$) Then ladder$ = "": Exit Function
  38.     ReDim TheList(1 To 1) As connectType, listPlace
  39.     ReDim wl$(1 To 1)
  40.  
  41.     start! = Timer(.001)
  42.     Split wordList$(Len(w1$)), " ", wl$()
  43.     connect$ = w1$
  44.  
  45.     newConnect:
  46.     'progress
  47.     'Print "Connect word is "; connect$; UBound(wl$); listPlace;
  48.     For i = 1 To UBound(wl$)
  49.         If oneChange%(connect$, wl$(i)) Then
  50.             If TheList(1).connect = "" Then
  51.                 TheList(1).connect = connect$
  52.                 TheList(1).word = wl$(i)
  53.             Else ' add to list only if word isn't a connect
  54.                 found = 0
  55.                 For j = 1 To UBound(theList)
  56.                     If wl$(i) = TheList(j).connect Then found = -1: Exit For
  57.                 Next
  58.                 If found = 0 Then
  59.                     cAppend TheList(), connect$, wl$(i)
  60.                 End If
  61.             End If
  62.             If wl$(i) = w2$ Then done = -1: Exit For
  63.         End If
  64.     Next
  65.     If done = 0 Then
  66.         listPlace = listPlace + 1
  67.         If listPlace > UBound(TheList) Then
  68.             ladder$ = "Could NOT connect " + w1$ + " to " + w2$
  69.         Else
  70.             connect$ = TheList(listPlace).word
  71.             GoTo newConnect
  72.         End If
  73.     Else
  74.         'should be able to backtrack our path?
  75.         ladder$ = "Could connect " + w1$ + " to " + w2$
  76.         target$ = w2$: trail$ = w2$
  77.         again:
  78.         For i = 1 To UBound(theList)
  79.             If TheList(i).word = target$ Then target$ = TheList(i).connect: trail$ = target$ + " > " + trail$: GoTo again
  80.         Next
  81.         ladder$ = ladder$ + Chr$(10) + trail$
  82.     End If
  83.     ladder$ = ladder$ + Chr$(10) + Str$(Timer(.001) - start!) + " secs, TheList() has" + Str$(UBound(theList)) + " items."
  84.  
  85. Sub Split (SplitMeString As String, delim As String, loadMeArray() As String)
  86.     Dim curpos As Long, arrpos As Long, LD As Long, dpos As Long 'fix use the Lbound the array already has
  87.     curpos = 1: arrpos = LBound(loadMeArray): LD = Len(delim)
  88.     dpos = InStr(curpos, SplitMeString, delim)
  89.     Do Until dpos = 0
  90.         loadMeArray(arrpos) = Mid$(SplitMeString, curpos, dpos - curpos)
  91.         arrpos = arrpos + 1
  92.         If arrpos > UBound(loadMeArray) Then ReDim _Preserve loadMeArray(LBound(loadMeArray) To UBound(loadMeArray) + 1000) As String
  93.         curpos = dpos + LD
  94.         dpos = InStr(curpos, SplitMeString, delim)
  95.     Loop
  96.     loadMeArray(arrpos) = Mid$(SplitMeString, curpos)
  97.     ReDim _Preserve loadMeArray(LBound(loadMeArray) To arrpos) As String 'get the ubound correct
  98.  
  99. Sub cAppend (arr() As connectType, cWrd$, w$)
  100.     ReDim _Preserve arr(LBound(arr) To UBound(arr) + 1) As connectType
  101.     arr(UBound(arr)).connect = cWrd$
  102.     arr(UBound(arr)).word = w$
  103.  
  104. Function oneChange% (last$, test$)
  105.     For i = 1 To Len(last$)
  106.         If Mid$(last$, i, 1) <> Mid$(test$, i, 1) Then strike = strike + 1
  107.     Next
  108.     If strike = 1 Then oneChange% = -1
  109.  

The times for each ladder start and end inside the Ladder sub, the over all time for the set of ladder calls PLUS the time to load the words from file is listed at the very end:
 
word ladder v3.PNG
« Last Edit: September 08, 2021, 03:26:04 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Word ladder - Rosetta Code
« Reply #13 on: September 08, 2021, 03:36:31 pm »
You know checking for redundancies could be time consuming, if I just keep adding to TheList then v2 where I preserve the path may save time after all! Let's see...

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Word ladder - Rosetta Code
« Reply #14 on: September 08, 2021, 04:11:43 pm »
No not going to work:
girl to lady took 45 secs with 25,369 items v3

v4 is v2 without redundancy checks now takes 601.85 secs with 3,251,469 items.
Remember processing paths took 3 mins longer when I did remove redundancies.

I am letting alien to drool run but it is going to take hours and that is if items does not exceed the limit of Longs.