# Shortening Programs

### #1

Posted 03 February 2014 - 09:27 AM

### #2

Posted 04 February 2014 - 02:59 AM

### #3

Posted 05 February 2014 - 07:23 AM

### #4

Posted 05 February 2014 - 05:38 PM

`RandInt(1,7)`

and `RandInt(1,7`

do the same thing (the second one will not throw an error).
### #5

Posted 08 February 2014 - 04:31 AM

### #6

Posted 08 February 2014 - 10:10 AM

This works, too:

`{1,2,3->List 1`

### #7

Posted 08 February 2014 - 11:08 PM

### #8

Posted 09 February 2014 - 03:49 AM

### #9

Posted 09 February 2014 - 05:10 PM

Here is a good Casio Basic OS 2.0 topic that I just found: http://community.cas...icks-from-cfxm/

### #10

Posted 09 February 2014 - 11:12 PM

Omitting parentheses is a bad habit.

The TI community does it often enough...

### #11

Posted 10 February 2014 - 09:32 AM

### #12

Posted 10 February 2014 - 01:08 PM

I actually meant that omitting theThe TI community does it often enough...

**closing**parenthesis is a bad habit.

Most of these websites are long gone but Caspro's site is still online: http://www.spiderpixel.co.uk/caspro/Does anyone know/can anyone find any of these tips and tricks?

The getkey conversion stuff is one of my favorites:

C2) If you want to convert Getkey codes for keys 1-9 into the actual

number that was pressed then the long way to do it is:

Getkey->A

A=72=>1->G:A=62=>2->G:A=52=>3->G

A=73=>4->G:A=63=>5->G:A=53=>6->G

A=74=>7->G:A=64=>8->G:A=54=>9->G

That takes 84 steps. The short way to do it is:

.1Getkey

2-Ans+31Frac Ans->G

which only takes 15 steps. Or to also detect the number 0 then use:

.1Getkey

2-Ans+31Frac Ans+2(Ans=7.1->G

Also in reverse to convert numbers 1-9 into Getkey codes use:

?->N

(N-1)/3 ;don't use reciprocal or get rounding errors

72+Ans-31Frac Ans->G

If you want to take into account the number 0 as well then use:

?->N

(N-1)/3 ;don't use reciprocal or get rounding errors

72+Ans-31Frac Ans-11(N=0->G

C3) To convert Getkey codes for letters A~Z into numbers 1~26 use:

.1Getkey

6-10Frac Ans->R

8-Int Ans+5R+R(R<3->G

### #13

Posted 11 February 2014 - 12:55 PM

ex1)

If C

Then Locate 1,1,"True"

IfEnd

Instead of above;

C=>Locate 1,1,"True"

ex2)

For example, given integer N, you want to map to cyclic numnber A, such like 1->2->3->1->2->......., you don't need any If statement, just write;

1+N-3Int(N/3)->A

simple isn't it?

Any integer can be classified in its residue system.

This is useful for example when you want to select menu item using arrow keys, cursor comes to very bottom of menu items, then it goes to top of the menu.

ex3)

If you want to get how many digits of given integer N, you do not need to devide by 10^n and do mamy calculation, just write;

1+Int(log(N))

This can be apllied to following case;

Locate 1,1,N

Locate 2+Int(log(N)),1,"digits"

When N is 123, you will get

123 digits

on the display.

When N is 98765, you will get

98765 digits

on the display.

The string "digits" comes at proper column with one space.

**Edited by Krtyski, 12 February 2014 - 12:27 AM.**

### #14

Posted 15 February 2014 - 02:32 AM

You can also use the StrLen( command which is easier for me.

I use Frac(N/X)*X for cyclic numbers where N is the number and X is the base.

### #15

Posted 15 February 2014 - 10:10 AM

### #16

Posted 15 February 2014 - 12:31 PM

As you said Frac(N/X)*X looks better because of fewer steps.

3298:

Thanks, I should take it into account.When internal precision is 15 digits, Frac(1.00000000000001) gives you 0 not 1x10^-14.Is this the case?

**Edited by Krtyski, 15 February 2014 - 12:50 PM.**

### #17

Posted 16 February 2014 - 11:22 AM

But going back to the original topic: You can sometimes save a few bytes by omitting multiplication symbols when the symbol after it is not a digit. (There may be other cases where it errors, but I only know about the case where you try A*2; in that case, just reverse it so it becomes 2*A, which can be optimized into 2A.) The manual says something about this implicit multiplication having higher priority than normal multiplication, so this may lead to different results. (If A is 1.75, then Int 2A is 3 because the implicit multiplication has higher priority than Int, but Int 2*A is 3.5 because the normal multiplication has lower priority.) This may lead to more or less necessary parentheses, depending on the formula, but I believe in most cases it's possible to get away with less parentheses, just reorder the formula a bit. (Let's pretend the 2 in the Int 2*A from above was a variable instead which could have a fractional part, and we want the 3.5 without the multiplication symbol, don't write (Int 2)A, but write AInt 2. Though if the 2 shall stay a literal number, just optimize the Int away, since 2 is already an integer number.)

Another similar thing: The fraction sign entered via can replace the division symbol not only for numbers, but also for variables, and with its different priority it could also help you avoid parentheses. Try this: N-XInt N_X (where _ is the fraction symbol, of course.) With the division symbol you would need parentheses around N/X to make it work correctly, but the fraction symbol works without them. Even if you omit the ")" at the end, you save a byte for the "(".

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users