Calculator Programming (TI-BASIC)

I’ve been playing around with TI-BASIC programming in the last couple of [boring] days at school. I recently created a nice little quadratic formula application for my TI-84+ graphing calculator. It comes in handy quite often in geometry class.

I took a week-long class at the University of Washington to learn the basics of C++ programming, and that has definitely helped in picking up TI-BASIC. For example, terms like for and while loops are familiar, as well as the layout of an application. Of course, TI-BASIC is much more, you guessed it, basic. But hey, what else are you going to do in school? :wink:

So, what kind of applications have you guys created? What apps do you use on your calculators?

Wow.

Back when I was taking engineering classes I programmed in boring things like numerical approximation methods or equation solving methods. Just things that would possibly be needed for questions on midterms or finals. For homework questions I usually crunched the equations by hand or used a proper computer.

That was on HP calculators. Never used a TI.

I never used a TI for school, but I used a friend’s TI for a while and programmed blackjack and keno games into it. Its limited display stifled my creativity.

My HP graphing calc, on the other hand… I programmed Pong, Pac Man and Pole Position into the thing in one semester of high school. Kinda goes to show how boring my teachers were…

Nowadays people are downloading modified Nintendo ROMs onto their super-duper-solve anything-calculator. Some of these models do way too much work for the student, leaving them dumber than dirt. Seriously, I took upper division physics with one kid who couldn’t do a simple integral without whipping out his HP.

Do yourself a favor and dump the whiz-bang doohickey. Grab a $5 scientific calculator that does trig and exponentials and that should get you all the way through your PhD if you work hard enough… and you’ll be smarter for all the work.

Or, as Harper will recommend, grab a slide rule. It’s just damn cool.

Haha yeah. That is why I learn everything without it then use it just too speed things up. I probably could be in a higher math class if all I did was punch everything into a calculator. That takes just about no brains. It basically turns into memorizing an equation and substituting in everything.

I’ve got Casio graphic calculator. I made quite a few probgrammes with it. I think the language is CBasic, but I’m not too sure. My programmes were different ones, some small bits to trick people into thinking my calculator gave out 5 when asked to calculate 2+2, there was a programme that said “Hacking the matrix” and run a line of zeros and ones at the top of the screen. If you pressed a button it would stop and a sign would appear saying “Do not disturb”. I gave it to my maths teacher she looked at it for some time and said it might be dangerous for my calculator. I said “What, hacking the matrix? Very dangerous!” The whole class was laughing(or at least the ones who knew the programme).

I also made a small game called Adventures of the Eight. I never finished it, because the refresh rate got too slow as I added to the game, so I just gave up. I made some other programmes, but can’t think of any right now.

A friend of mine made this whole project that allowed him to render different fractals with all sorts of settings, resolutions, etc on his calculator. He even added colour later. The only problem, the calculator is slow and it would take ages to render one fractal. But it was cool.

He and I also drew on the calculator using the memory feature and geometrical shapes. Ahh, the boring school times…

Here’s a fun programming concept to work on. We’ll play with the factorial function.

Your algebra book should have a definition of how to calculate a factorial.

The factorial is the function on your calculator with the !

There is a basic definition here (only pay attention to the top half of the page).

The important part is that 0! is defined to be equal to 1

0! = 1
1! = 1
2! = 2 * 1
3! = 3 * 2 * 1
4! = 4 * 3 * 2 * 1

You get the idea. The numbers get really big really quick.

So write a program that uses a loop to calculate the factorial. How big can you go before the calculator overflows and the result is no longer exact?

If I were doing it in C++, I’d just use for.

answer=1;
for(a=whatever;a>0;a–)
{
answer = answer*a;
}

There’s probably a mistake or two in there, but the principle is simple. I’d do the same on the calculator, it’d just be a bit more cumbersome to type out.

I have one. They are.

(in best Guiness commercial impersonation) Multiply numbers by adding them? Brilliant!

I’m proud of you for starting a nerd corner, Tyler. The quadratic equation is useful for many applications. Deriving the quadratic formula is very instructive as well.

I used to road test my programmable calculators by writing either a rectangular or trapezoidal integrating routine and make it solve for Pi. I used to make it calculate 200,000 steps or so and have it run for four or five days. I think with that resolution I could get solutions that were only good to a part in 100,000. I did this first for an SR-56, one of TI’s first programmables and the first to be marketed for under $100. Then for an HP-21 and finally an HP-29C. This was in the 70’s and I have since abandoned all programmable calculators. The sentence is, “slide rules.”

I guess if this thread is for all nerdy topics, I may as well mention that I bought a 160 gig HDD (upgraded from 30 gig!) for my laptop, and am now dual booting Win XP and Ubuntu Linux (7.04 Feisty Fawn) with it. w00t.

Yep, that makes sense.

OK, I’ll make my “triple post” a worthwhile one. I wrote a “trick” app similar to what Ivan described.

Here’s the code. It’s pretty self explanatory (as most BASIC is):

: Prompt A,B
: ((A+B)+randInt(1,9))[/I]

Although, if I showed this app to somebody they would probably just think I was a crap programmer and not be “tricked.” :stuck_out_tongue:

Yes, but the next lesson is to do it recursively. :slight_smile:

The factorial has a straightforward recursive definition:

base case: 0! = 1
recursive case: n! = n*(n-1)! for n > 0

Now write a factorial function in C that calculates the factorial using recursion. No loops allowed.

I did a quick look at a TI-BASIC wiki and recursive functions in TI-BASIC are also possible but require some programming tricks. We’ll jump away from TI-BASIC for this recursion lesson since TI-BASIC will just complicate things. (HP calculators can do recursion without funky tricks)

Recursion sucks. It eats up memory and processor time. And the way you’re teaching us just goes on to prove that you’re a unicyclist. Very unconventional. The traditional text-book way would be to solve your problem using recursion, then knock it because it’s too slow and solve it again with loops to make everyone happy and impressed with how much optimising your algorythms helps.

Okay, a programme in C. Let’s see…


int fractal(int number)
{
   if(number>0)
      {
          return (fractal(number-1)*number);
       }
     return 1;
}

I think this is wrong and could be made easier, but it’s half six in the morning, I’m sore from working the whole weekend and I want my breakfast. Plus, recursion sucks anyway. But the idea is there…

Edit: I’ll just put it in code, because the forum messes up the formatting.

Okay, Ivan, if you’re the expert here, then tell us how much extra memory and time (in processor cycles) we’re wasting, and how that scales in comparison to a loop statement? Let’s assume we’re working with a PowerPC processor, and that our compiler cannot optimize recursive functions.

Now that you’ve knocked that one out, tell us how to do things such as traversing a tree or producing a fractal without using recursion? Which method (recursive or non-recursive) produces code that is easier to read and/or maintain?

What’s all the worry about waste, anyways? With GBs of RAM and 100s of GBs of hard drive space on a typical desktop, storage isn’t the issue. And, depending on your algorithm, the number of cycles used to push a call onto the stack is usually much smaller than the number of cycles consumed by the rest of your function. With a 3 GHz processor, you won’t be wasting much time waiting for recursion.

It’s easy to squawk “Recursion sucks!” like a parrot, but it goes to show your inexperience as a programmer. Sure it’s not the first method most programmers will consider, but it can be quite a powerful tool. Don’t go throwing it out of your toolkit so soon!

I knew one of the other programming geeks here would jump in to defend recursion. :smiley:

My purpose in introducing the factorial was to lead on to the recursive example. Tyler took a short programming course over the summer but didn’t learn about recursion. I figured this would be a good place to introduce the concept so he can have a lesson that can turn his brain inside out and keep him occupied during the first few boring days of the school year. Let’s see if he takes the bait.

Recursion is very useful and is a very important programming construct. It makes for very clean implementations of some tasks like recursing through a directory structure.

Recursion can blow the stack if you recurse too deeply. But it is also possible to eliminate that by making the function tail recursive. Any competent optimizing compiler will convert tail recursion to an iterative form that does not grow the stack. Anyone who has a computer science degree will know and understand tail recursion. But it’s also something that is typically covered in a junior year CS class so we’ll avoid turning this into an upper division CS class and just focus on the basic concept of recursion.

And believe it or not, there are some functional programming languages where all loops are accomplished via recursion. No for loops. No while loops. Just recursion.

Wow, talk about overreacting…

Duh, it’s a tool… Anything is a tool. I’m just saying there are usually better tools than recursion, you just have to look for them. And I like your lazy-arse approach: recursion is easy to implement and who cares about processor time anyway. Say that to a 3D modelling software developer.

And yes, I’m not a programmer at all. I stopped programming about 4 years ago(if you don’t count the calculator moments). So, yeah. Don’t go knocking my programming skills, because I have none.

This thread inspired me to start learning some Casio Basic for my fx-9750G PLUS. The syntax is a little weird for me since the only other programming language I can do anything in his Python, but it’s kinda fun.

I’m reading some more of Beginning Python From Novice to Professional tonight. Learning some Python. Seems to be a good book. I might have to revive the Python thread that was going on recently.