I am trying to create a program that simplifies radicals in TI-BASIC. However, one FOR loop seems to be only completing one iteration while the rest work fine. Here is the code:
Input "Root=",A
Input "Radical=",B
B→Z
ClrList L₃
prgmPRMNTOL1
prgmGETPRIME
The FOR loop in question starts here...
For(Y,1,10)
0→Z
For(X,1,dim(L₂))
If L₁(Y)=L₂(X)
Then
Z+1→Z
End:Disp Z
End
If Z≥A
Then
int(Z/A)*A→C
int(Z/A)→D
For(T,1,D)
L₁(Y)→L₃(1+dim(L₃))
End
For(R,1,C)
ClrList L₄
For(S,1,dim(L₂))
If L₂(S)=L₁(Y) and C>0
Then
–1→L₂(S)
C-1→C
End
End
For(Q,1,dim(L₂))
If L₂(Q)≠–1
Then
L₂(Q)→L₄(1+dim(L₄))
End
End
ClrList L₂
For(Q,1,dim(L₄))
L₄(Q)→L₂(Q)
End
End
End
...and ends here.
1→E
For(M,1,dim(L₃))
E*L₃(M)→E
End
1→F
For(N,1,dim(L₂))
F*L₂(N)→F
End
Disp "OUTSIDE",E,"ROOT",A,"INSIDE",F
The program works perfectly besides the fact that this one loop only runs once. I will post prgmPRMNTOL1
and prgmGETPRIME
as well if necessary, though they probably do not have any impact as they modify only L₁
and L₂
.
EDIT: Added a indented version.
Input "Root=",A
Input "Radical=",B
B→Z
ClrList L₃
prgmPRMNTOL1
prgmGETPRIME
For(Y,1,10)
0→Z
For(X,1,dim(L₂))
If L₁(Y)=L₂(X)
Then
Z+1→Z
End
End
If Z≥A
Then
int(Z/A)*A→C
int(Z/A)→D
For(T,1,D)
L₁(Y)→L₃(1+dim(L₃))
End
For(R,1,C)
ClrList L₄
For(S,1,dim(L₂))
If L₂(S)=L₁(Y)
Then
–1→L₂(S)
End
End
For(Q,1,dim(L₂))
If L₂(Q)≠–1
Then
L₂(Q)→L₄(1+dim(L₄))
End
End
ClrList L₂
For(Q,1,dim(L₄))
L₄(Q)→L₂(Q)
End
End
End
1→E
For(M,1,dim(L₃))
E*L₃(M)→E
End
1→F
For(N,1,dim(L₂))
F*L₂(N)→F
End
Disp "OUTSIDE",E,"ROOT",A,"INSIDE",F