... .. ... 005 53 ( 008 55 / 011 45 y^x 014 75 - 017 54 ) 020 42 STO
003 76 2nd Lbl 006 43 RCL 009 01 1 012 53 ( 015 43 RCL 018 54 ) 021 25 25
004 75 - 007 25 25 010 00 0 013 08 8 016 26 26 019 59 2nd Int ... .. ...
EXAMPLES
This page shows two programs written in T Language. As you will notice, we are far away from basic AOS Language !
Having said that, never forget your TI 59 capacities. Designing a program for such a calculator keeps challenging: memory is shared between program and registers and is limited to 960 bytes. The more memory you use, the less programming steps you have (and vice versa)...
Luckily, the T Compiler will help you finding the right balance between these two critical resources.
QUADRATIC EQUATION
PRE-REQUISITES
T Language is based on C Language. Please, be trained to C Progamming techniques before coding in T Language.
QUADRATIC EQUATION
This program is very simple as it doesn't include any array or subroutine calls.
For macros descriptions, see here.
#include <math.h>
#include <stdio.h>
#include <unistd.h>
#define input(identifier, stop) printf("? "); scanf("%lf", &identifier)
#define inputKey(identifier, key, stop) printf("%s ? ", key); scanf("%lf", &identifier)
#define display(expression) printf("%lf\n", expression)
#define pause(expression, duration) printf("%lf\n", expression); sleep(duration)
void main()
{
double a;
double b;
double c;
double delta;
inputKey(a, "A", true);
inputKey(b, "B", true);
inputKey(c, "C", false);
// Compute delta
delta=b*b-4*a*c;
if (delta>=0)
{
// Real solutions
display((-b-sqrt(delta))/(2*a));
display((-b+sqrt(delta))/(2*a));
}
else
{
// No solutions
display(99999999);
}
}
SUDOKU SOLVING
This program is far more advanced. It uses arrays and subroutine calls with arguments passed either by value or by reference.
As is, it doesn't fit within the calculator memory. For an optimized version that's working fine (sudoku2.c), please download the T Compiler package.
#include <math.h>
#include <stdio.h>
#include <unistd.h>
#define input(identifier, stop) printf("? "); scanf("%lf", &identifier)
#define inputKey(identifier, key, stop) printf("%s ? ", key); scanf("%lf", &identifier)
#define display(expression) printf("%lf\n", expression)
#define pause(expression, duration) printf("%lf\n", expression); sleep(duration)
double grid[9];
double trace[9];
double getDigit(double number, double col)
{
double left;
double digit;
// Get a digit in a number
// with 0 <= col <= 8 starting from left
left=trunc(number/pow(10, 8-(int)col));
digit=left-trunc(left/10)*10;
return digit;
}
void setDigit(double *number, double col, double newDigit)
{
double oldDigit;
oldDigit=getDigit(*number, col);
// Set a digit in a number
// with 0 <= col <= 8 starting from left
*number-=oldDigit*pow(10, 8-(int)col);
*number+=newDigit*pow(10, 8-(int)col);
}
void findMissingDigits(double fromRow, double toRow, double fromCol, double toCol, double *missing)
{
double row;
double col;
double digit;
row=fromRow;
while (row<toRow+1)
{
col=fromCol;
while (col<toCol+1)
{
// Check whether the cell is not empty (digit!=0)
digit=getDigit(grid[(int)row], col);
if (digit!=0)
{
// Remove the digit from the missing list
setDigit(missing, digit-1, 0);
}
col+=1;
}
row+=1;
}
}
void rollback(double *row, double *col)
{
double stop;
// Remove the cell digit in the trace
setDigit(&trace[(int)*row], *col, 0);
// Move backward to the previous cell digit
stop=0;
while (stop==0)
{
if (*col>=1)
{
*col-=1;
}
else
{
if (*row>=1)
{
*row-=1;
*col =8;
}
else
{
stop=1;
}
}
if (getDigit(trace[(int)*row], *col)!=0)
{
// Remove the cell digit in the grid
setDigit(&grid[(int)*row], *col, 0);
stop=1;
}
}
}
void displayTrace()
{
// printf("\n");
// printf("%09.0lf %09.0lf\n", trace[0], grid[0]);
// printf("%09.0lf %09.0lf\n", trace[1], grid[1]);
// printf("%09.0lf %09.0lf\n", trace[2], grid[2]);
// printf("%09.0lf %09.0lf\n", trace[3], grid[3]);
// printf("%09.0lf %09.0lf\n", trace[4], grid[4]);
// printf("%09.0lf %09.0lf\n", trace[5], grid[5]);
// printf("%09.0lf %09.0lf\n", trace[6], grid[6]);
// printf("%09.0lf %09.0lf\n", trace[7], grid[7]);
// printf("%09.0lf %09.0lf\n", trace[8], grid[8]);
// printf("\n");
}
void main()
{
double row;
double col;
double digit;
double missing;
double digitInTrace;
double stop;
double i;
double counter;
// grid[0]= 80020060;
// grid[1]=107000000;
// grid[2]= 400003;
// grid[3]=300000090;
// grid[4]= 26000080;
// grid[5]= 1007;
// grid[6]=800009000;
// grid[7]= 14000020;
// grid[8]=200830000;
// Set the trace to zero
row=0;
while (row<9)
{
trace[(int)row]=0;
row+=1;
}
// Parse the grid
counter=1;
row=0;
while (row<9)
{
col=0;
while (col<9)
{
// printf("%lf\n", counter+(row*10+col)/100);
pause(counter+(row*10+col)/100, 1);
counter+=1;
// Check whether the cell is empty (digit=0)
digit=getDigit(grid[(int)row], col);
if (digit==0)
{
// List of missing digits
missing=123456789;
// Find which digits are missing in the row
findMissingDigits(row, row, 0, 8, &missing);
// Find which digits are missing in the column
findMissingDigits(0, 8, col, col, &missing);
// Find which digits are missing in the 3x3 cells area
findMissingDigits(trunc(row/3)*3, trunc(row/3)*3+2, trunc(col/3)*3, trunc(col/3)*3+2, &missing);
if (missing!=0)
{
// Get a missing digit greater than the cell digit in the trace
digitInTrace=getDigit(trace[(int)row], col);
i=0;
stop=0;
while (stop==0)
{
digit=getDigit(missing, i);
if (digit>digitInTrace)
{
// Found one
// Set the cell digit
setDigit(&grid[(int)row], col, digit);
setDigit(&trace[(int)row], col, digit);
stop=1;
}
else
{
i+=1;
if (i==9)
{
// Didn't find any
// Rollback
rollback(&row, &col);
stop=1;
}
}
}
}
else
{
// Rollback
rollback(&row, &col);
}
}
else
{
col+=1;
}
}
row+=1;
}
// displayTrace();
}