0

So I want to make a program that will use the Collatz Conjecture on numbers I put in, but I can't figure out a way to make the program be able to tell between even and odd numbers. I know it's x%2==0 for odd in Python, but I can't seem to find a function for it in the catalog in my calculator, or a way to algebraically do that. If anyone is familiar with that or has any suggestions, that'd be great. Thanks!

Makoto
  • 104,088
  • 27
  • 192
  • 230
Van Nuysmacht
  • 19
  • 1
  • 1

3 Answers3

5

remainder( only exists on newer firmware. The best way to do this, at no cost to your size, is to use fPart(, which is only one byte instead of two.

Here is an example:

[Your Number]->A
If fPart(A/2
Then
Disp "ODD
Else
Disp "EVEN
End

... which can be shortened to:

Disp sub("EVENODD ",1+8fPart(A/2),4
Timtech
  • 1,224
  • 2
  • 19
  • 30
  • 1
    And the `fPart(A/2` works because the `fPart(` command returns the fractional part of a number, and the `If` conditional interprets any nonzero number to mean true. – user3932000 Dec 26 '16 at 23:17
  • Right. If you actually want the remainder of A/B, use `BfPart(A/B` instead. – Timtech Jan 14 '17 at 20:47
4

The TI-84+ uses an updated version of TI-83 TI-BASIC. You can use the remainder() function on this calculator to determine whether a number is divisible by 2.

remainder(20/2) evaluates to 0.

You can then use basic conditional logic to print whatever output you want!

For documentation on TI-BASIC, check out http://tibasicdev.wikidot.com/

Nate Gardner
  • 1,577
  • 1
  • 16
  • 37
  • I never saw remainder( on my ti-84, but I use fPart( -it returns the decimal part of any number – Private Caller Dec 07 '16 at 23:05
  • @PrivateCaller `remainder(` was introduced in the 2.53 MP operating system. I would also recommend using `fPart(` if at all possible. – Timtech Feb 13 '17 at 16:15
  • Nate, I know what you're trying to say, but remember that `remainder(` technically isn't TI-83 BASIC in the sense that TI-83 does not support the 2.53MP OS, which is the one that introduced the command. – Timtech Feb 13 '17 at 16:17
0

Here's a more efficient way:

/*your number goes here*/

if fPart(Ans/2):Then
Disp "Odd
Else
Disp "Even
End

Putting the value of the number in your code automatically stores it inside the "Ans" variable.

It would more efficient to use the "Ans" variable in your if statement instead of using up additional memory by creating an another variable.

This is because the value of "Ans" is stored in a reserved part of the calculator's memory, which won't take up extra space.

It is also faster than "the real, complex, list, matrix, and string variables; and subsequently, you should try to use it as much as possible."

Source:

http://tibasicdev.wikidot.com/ans

Alex Zhang
  • 123
  • 1
  • 10