Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
phone number to words
#11
reply to @Pete last reply

pretty sure the method i outlined above is quicker, the file is ready already in reply #4

the flaw of this idea is that there are no numbers assigned for 0 and 1

BTW here is code i used to make the file:
Code: (Select All)
_Title "Make 7 letter Phone Words txt file"
Type WN
    As String * 7 W, N
End Type
Dim wdList(1 To 24029) As WN
Open "7 Letter Words.txt" For Input As #1
For i = 1 To 24029
    Input #1, wdList(i).W
    wdList(i).N = W2N$(wdList(i).W)
    'Print wdList(i).N, wdList(i).W
    'Sleep
Next
Close #1
QuickSort 1, 24029, wdList()
'For i = 1 To 20
'    Print wdList(i).N, wdList(i).W
'Next
Open "7 Letter Phone Words.txt" For Output As #1
For i = 1 To 24029
    Print #1, wdList(i).N, wdList(i).W
Next
Close #1
Print "number to word file is ready"

Function W2N$ (w$)
    For i = 1 To Len(w$)
        Select Case Asc(UCase$(w$), i)
            Case 65 To 67: d$ = "2" ' ABC
            Case 68 To 70: d$ = "3" ' DEF
            Case 71 To 73: d$ = "4" ' GHI
            Case 74 To 76: d$ = "5" ' JKL
            Case 77 To 79: d$ = "6" ' MNO
            Case 80 To 83: d$ = "7" ' PQRS
            Case 84 To 86: d$ = "8" ' TUV
            Case 87 To 90: d$ = "9" ' WXYZ
        End Select
        rtn$ = rtn$ + d$
    Next
    W2N$ = rtn$
End Function

Sub QuickSort (start As Long, finish As Long, array() As WN)
    Dim Hi As Long, Lo As Long, Middle$
    Hi = finish: Lo = start
    Middle$ = array((Lo + Hi) / 2).N 'find middle of array
    Do
        Do While array(Lo).N < Middle$: Lo = Lo + 1: Loop
        Do While array(Hi).N > Middle$: Hi = Hi - 1: Loop
        If Lo <= Hi Then
            Swap array(Lo), array(Hi)
            Lo = Lo + 1: Hi = Hi - 1
        End If
    Loop Until Lo > Hi
    If Hi > start Then QuickSort start, Hi, array()
    If Lo < finish Then QuickSort Lo, finish, array()
End Sub
b = b + ...
Reply
#12
I avoid making recursive calls within a sub to avoid stack space issues. Those were a big deal in QB, but not so much in QB64. I would assign a variable, exit the sub, and the next statement would determine to either re-loop the subroutine or move on.

Code: (Select All)
Do
MySub x
If x = 1 Then Exit Do
Loop

Sub MySub (x)
a = Int(Rnd * 20)
If a = 5 Then x = 1
End Sub

Pete
Reply
#13
(07-02-2024, 08:05 PM)Pete Wrote: I avoid making recursive calls within a sub to avoid stack space issues. Those were a big deal in QB, but not so much in QB64. I would assign a variable, exit the sub, and the next statement would determine to either re-loop the subroutine or move on.

Code: (Select All)
DO
MySub x
IF x = 1 THEN EXIT DO
LOOP

Mysub
a = INT(RND * 20)
IF a = 5 THEN x = 1
END SUB

Pete

ah took me a moment to figure what was recursive, oh the QuickSort.

That one has been dependable for years, unless miss-coded there is no danger of a runaway stack space blowing out memory, it needs less and less space on each call. on average it divides in half each time and from math we know the limit of the sum of halfing is 2, or twice the array size.

Ha just made that up, sounds pretty good right? it may be actually correct Smile
Zenos Tortoise and Hare Paradox is not.
b = b + ...
Reply
#14
OMG. I guess old age is setting in. I haven't coded anything in 2-months and already I've forgotten how to make a subroutine call. Now edited. Oh well, at least I'm retired and not operating a school bus or worse yet, pretending to run the country. Oh, and I have a cold... AHHHCHOOOO.

Pete Big Grin
Reply




Users browsing this thread: 1 Guest(s)