108 lines
2.5 KiB
Text
108 lines
2.5 KiB
Text
Type Rueda
|
|
nombre As String * 1 'Single character for wheel name
|
|
valor As String 'String * 3 in QBasic (Maximum 3 characters needed for wheel values)
|
|
index As Integer
|
|
End Type
|
|
|
|
' Main program
|
|
Print "Intersecting Number Wheel group:"
|
|
|
|
' First test case
|
|
Dim wheels1(0) As Rueda
|
|
InitWheel wheels1(0), "A", "123"
|
|
Print " A: [1 2 3]"
|
|
Print " Generates:"
|
|
Print " ";
|
|
Mostrar GirarRuedas$(wheels1())
|
|
|
|
Print Chr$(10); "Intersecting Number Wheel group:"
|
|
' Second test case
|
|
Dim wheels2(1) As Rueda
|
|
InitWheel wheels2(0), "A", "1B2"
|
|
InitWheel wheels2(1), "B", "34"
|
|
Print " A: [1 B 2]"
|
|
Print " B: [3 4]"
|
|
Print " Generates:"
|
|
Print " ";
|
|
Mostrar GirarRuedas$(wheels2())
|
|
|
|
Print Chr$(10); "Intersecting Number Wheel group:"
|
|
' Third test case
|
|
Dim wheels3(1) As Rueda
|
|
InitWheel wheels3(0), "A", "1DD"
|
|
InitWheel wheels3(1), "D", "678"
|
|
Print " A: [1 D D]"
|
|
Print " D: [6 7 8]"
|
|
Print " Generates:"
|
|
Print " ";
|
|
Mostrar GirarRuedas$(wheels3())
|
|
|
|
Print Chr$(10); "Intersecting Number Wheel group:"
|
|
' Fourth test case
|
|
Dim wheels4(2) As Rueda
|
|
InitWheel wheels4(0), "A", "1BC"
|
|
InitWheel wheels4(1), "B", "34"
|
|
InitWheel wheels4(2), "C", "5B"
|
|
Print " A: [1 B C]"
|
|
Print " B: [3 4]"
|
|
Print " C: [5 B]"
|
|
Print " Generates:"
|
|
Print " ";
|
|
Mostrar GirarRuedas$(wheels4())
|
|
End
|
|
|
|
Function Girar$ (wheel As Rueda, dato() As Rueda)
|
|
wheel.index = (wheel.index + 1) Mod Len(wheel.valor)
|
|
c$ = Mid$(wheel.valor, wheel.index + 1, 1)
|
|
|
|
If isNumeric(c$) Then
|
|
Girar$ = c$
|
|
Exit Function
|
|
End If
|
|
|
|
For i = 0 To UBound(dato)
|
|
If dato(i).nombre = c$ Then
|
|
Girar$ = Girar$(dato(i), dato())
|
|
Exit Function
|
|
End If
|
|
Next
|
|
|
|
Girar$ = ""
|
|
End Function
|
|
|
|
Function GirarRuedas$ (wheels() As Rueda)
|
|
Static result As String
|
|
Static cnt As Integer
|
|
Const maxCnt = 20
|
|
Dim dato(UBound(wheels)) As Rueda
|
|
|
|
For i = 0 To UBound(wheels)
|
|
dato(i) = wheels(i)
|
|
dato(i).index = -1 'Initialize to -1 so first increment gives 0
|
|
Next
|
|
|
|
result = ""
|
|
For cnt = 0 To maxCnt - 1
|
|
result = result + Girar$(dato(0), dato())
|
|
Next
|
|
|
|
GirarRuedas$ = result
|
|
End Function
|
|
|
|
Sub InitWheel (w As Rueda, n As String, v As String)
|
|
w.nombre = n
|
|
w.valor = v
|
|
w.index = 0
|
|
End Sub
|
|
|
|
Function isNumeric (ch As String)
|
|
isNumeric = (ch >= "0" And ch <= "9")
|
|
End Function
|
|
|
|
Sub Mostrar (secuencia As String)
|
|
For i = 1 To Len(secuencia)
|
|
Print Mid$(secuencia, i, 1);
|
|
If i < Len(secuencia) Then Print " ";
|
|
Next
|
|
Print " ..."
|
|
End Sub
|