PDA

View Full Version : TI Programming help!



PlasbianX
October 8th, 2009, 04:14 PM
Okay so im making a program for my TI83 (all done within the calculator) that allows me to run the syracuse problem. Basically I have to check all whole numbers 1 through 100 to see how many integrals they have. When its finished, it has to display the number that had the highest amount, and what that amount was. How syracuse works is this: We take any whole number n greater than 0. If n is even, we halve it (n/2), else we do "triple plus one" and get 3n+1. The conjecture is that for all numbers this process converges to 1

My code is rather messy, but if anyone could help me out then it would be extremely appreciated. My problem is that it keeps looping continuously and won't ever find the answer. HALP!! :saddowns:


// X is the counter for which number the program is on
// R is the remainder of the fpart
// C is the counting number to see how many times the equation has been run
// H is the highest number of C
// Y is the highest number of X

0->X
0->R
0->C
0->H
0->Y
lbl A
(X+1)->X
X->Z

lbl B
Z->W
fpart(Z/2)->R

if R = 0
then
(W/2)->Z
(C+1)->C
else
((3W)+1)->Z
(C+1)->C
end

if Z > 1
then
goto B
else
if C > H
then
C->H
X->Y
0->C
goto A
else
goto A
end
end

if x = 100
then
disp H
display Y
else
goto A
end

Kalub
October 8th, 2009, 09:05 PM
fuck you and your math :(

PlasbianX
October 8th, 2009, 09:18 PM
fuck you and your math :(

>.>

HALP.

Warsaw
October 8th, 2009, 09:27 PM
Why are there so many ends? I'm willing to bet it has something to do with that.

PlasbianX
October 8th, 2009, 09:30 PM
Why are there so many ends? I'm willing to bet it has something to do with that.

Taking them out just yields the result "done"
I never learned how to program on these. Im just going by trial and error and I thought you always needed an end after an if then

PlasbianX
October 8th, 2009, 10:54 PM
Double Post! Finally got it. Looked up some info on loops and decided to use those in my program rather than using a ton of if-then's that pointed back towards themselves. Heres my new code:


// Syracuse Problem
// Allen Kowal
// Professor Dence
// October 9, 2009

// Number with most integrals: 97 with 118
// Comments not included on actual calculator program

// This clears out all variables before the program runs
// H is the record for integrals, Y is the number corresponding to this
// C is a counter for the amount of integrals, X is a counter for the numbers
// R is the remainder from the fpart check
0 -> X
0 -> R
0 -> C
0 -> H
0 -> Y
0 -> Z

// Loops this portion of the code until all values 1 through 100 have been run
While X < 100
(X+1) -> X
X -> Z

// Loops until the number cannot be divided anymore
While Z > 1
// Checks if the number is even or odd
// Each time the equation is run, the counter "C" is increased by 1
fpart(Z/2) -> R
If R=0
Then
// Even number
(Z/2) -> Z
(C+1) -> C
Else
// Odd number
((3Z)+1) -> Z
(C+1) -> C
End
End

// This checks to see if the current amount of integrals is higher than the record number of integrals
// If this is true, the value of "C" replaces "H" and "C" is reset. If false, "C" is just reset.
If C>H
Then
C -> H
X -> Y
0 -> C
Else
0 -> C
End

End
// Displays the end result
Disp "Number:"
Disp Y
Disp "Integrals:"
Disp H