User:Dinoguy1000/TI-89 Titanium programs
From Wikipedia, the free encyclopedia
This is a Wikipedia user page.
This is not an encyclopedia article. If you find this page on any site other than Wikipedia, you are viewing a mirror site. Be aware that the page may be outdated and that the user to whom this page belongs may have no personal affiliation with any site other than Wikipedia itself. The original page is located at http://en.wikipedia.org/wiki/User:Dinoguy1000/TI-89_Titanium_programs. |
This page has a sampling of some of my (IMHO) best work programming in 89 Titanium BASIC. I may add programs from time to time, or update existing ones, so be sure to check back once in a while.
This is a table of characters I use for specific situations. Note that a few of these will be compound substitutions used in lieu of a single character until such time as I can find a suitable replacement. | |
→ | Store to variable |
© | Comment |
‾ | Negative sign |
≠ | Not equal to |
≤ | Less than or equal to |
≥ | Greater than or equal to |
× | Multiply by |
… | Ellipsis |
|> | Right-pointing solid small triangle |
I've been experimenting with different lang settings with the source tag, this is a list of the ones which look pretty good:
- Smalltalk
Here's the ones that don't look so good:
- caddcl
- freebasic
Contents |
[edit] Programs
[edit] isbn_fmt()
A program which accepts an ISBN-10 or ISBN-13, with or without the check digit, calculates both ISBN-10 and ISBN-13 check digits, properly formats the ISBN into an ISBN-10 and an ISBN-13, and displays them with some basic information. The current version of the program doesn't actually calculate the ISBN-13 check digit, nor does it split the publisher number from the book number, but this is because I haven't been able to add these features yet.
Uncompiled size | Compiled size | Dependancies |
---|---|---|
2639 bytes | 2393 bytes | None |
:isbn_fmt() :Prgm :Local a,b,c,d,e,f,g,groupchk,h,i,j,k,l,y,z :©a = Input ISBN :©b = ISBN 9-digit base # :©c = Output ISBN-13 :©d = Output ISBN-10 :©e = ISBN-13 prefix :©f = Group # :©g = ISBN-13 check digit :©h = ISBN-10 check digit :©i = ISBN work number :© :©z = Mode settings :©y = Quit status (1=quit)© :©j = Group name? :© Publisher number? :setMode("14","2")→z :0→y :"978"→e : :Define groupchk(a)=Func : Local b,c,d,e,f : expr(left(a,1))→d : expr(mid(a,2,1))→e : expr(mid(a,3,1))→f : left(a,when(d=6,3,when(d=8,2,when(d=9,when(5≤e and e≤8,3,when(e=9,when(3≤f and f≤8,4,when(f=9,5,9)),2)),1))))→b : right(a,when(d=6,6,when(d=8,7,when(d=9,when(5≤e and e≤8,6,when(e=9,when(3≤f and f≤8,5,when(f=9,4,0)),7)),8))))→c : expr(b)→d : when(609<d and d<950 or 989<d and d<9934 or d=9969 or d=99900 or d=99907 or 99960<d,b&"-"&c&": Bad group #",{b,c}) :EndFunc : :Dialog : Title "ISBN-10 and ISBN-13 formatter" : Text "" : Text " Checks the accuracy of ISBNs, generates " : Text " ISBN-10 and ISBN-13 check digits, and" : Text " formats ISBN-10s and ISBN-13s." : Text "" : Text " Version 0.6α by Phillip Patriakeas" : Text "" :EndDlog :If ok=0 : 1→y :Loop : If y=1 : Exit : Dialog : Title "Enter ISBN" : Text "" : Text " Enter an ISBN-10 or ISBN-13." : Text " The check digit is optional." : Text " Non-numerical characters get stripped " : Text " before processing." : Text "" : Request "ISBN",a,0 : EndDlog : If ok=0 : Exit : dim(a)→h : For b,1,h : ord(mid(a,b,1))→c : when(c<48 or c>57,left(a,b-1)&right(a,dim(a)-b),a)→a : If dim(a)≠h Then : b-1→b : h-1→h : EndIf : EndFor : If h≠9 and h≠10 and h≠12 and h≠13 Then : Dialog : Title "Invalid ISBN" : Text "" : Text " The ISBN is the wrong length." : Text "" : Text " Valid ISBNs are either 10 or 13 digits long, " : Text " and this program can accept ISBNs without" : Text " the check digit." : Text "" : EndDlog : If ok=0 : Exit : Cycle : EndIf : when(h=12 or h=13,when(left(a,3)="279","279",e),e)→e : when(h=10,left(a,9),when(h=12 or h=13,mid(a,4,9),a))→b : groupchk(b)→f : If getType(f)="STR" Then : Dialog : Title "Invalid group number" : Text "" : Text " The group number in the ISBN " : Text " "&a&" is invalid." : Text "" : EndDlog : If ok=0 : Exit : Cycle : EndIf : f[2]→i : f[1]→f : f&"-"→d : e&"-"&d→c : string(mod(10-mod(sum(seq(expr(mid(e&a,j,1))*when(fPart(j/2)=0,3,1),j,1,12)),10),10))→g : 11-mod(sum(seq(expr(mid(a,j,1))*(11-j),j,1,9)),11)→h : when(h=11,"0",when(h=10,"X",string(h)))→h : Dialog : Title "ISBN analysis" : Text "" : Text " ISBN-13: "&c&i&"-"&g&" " : Text " ISBN-10: "&d&i&"-"&h : Text "" : Text " Group: "&f&" " : Text "" : EndDlog : If ok=0 : Exit :EndLoop :setMode("14",z) :EndPrgm
[edit] numdays()
A program which allows you to enter two dates and then calculates the total number of days between them. Note that the day count may be off in certain cases, as I have not yet fully tested/debugged it.
Uncompiled size | Compiled size | Dependancies |
---|---|---|
? bytes | ? bytes | None |
:numdays() :Prgm : Local a,b,c,d,d1,d2,darr,decarr,dispd,e,e1,e2,err,f,g,h,i,j,j1,j2,j3,k,m1,m2,marr,quit,setup,str,total,yarr,yr,yr1,yr2 : {"January","February","March","April","May","June","July","August","September","October","November","December"}→marr : {31,when(fPart(b/400)=0,29,when(fPart(b/100)=0,28,when(fPart(b/4)=0,29,28))),31,30,31,30,31,31,30,31,30,31}[a]→darr(a,b) : when(fPart(a/400)=0,366,when(fPart(a/100)=0,365,when(fPart(a/4)=0,366,365)))→yarr(a) : when(fPart(ceiling(a/10)/40)=0,3653,when(fPart(ceiling(a/10)/10)=0,3652,when(fPart(ceiling(a/10)/2)=0,3653,3652)))→decarr(a) : Define dispdate(m,d,y,s)=Func : Local a,b,d1,e,m1,s1,s2,s3,s4,yr1 : s[1]→s1 ©date format : s[2]→s2 ©separator : s[3]→s3 ©leading zeros : s[4]→s4 ©era format : [["January","February","March","April","May","June","July","August","September","October","November","December"]["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]["1","2","3","4","5","6","7","8","9","10","11","12"]][when(s1=1 or s1=5,1,when(s1=2 or s1=6,2,3)),m]→a : © leading zeros - months : when(s3=2 and m<10,"0"&a,a)→m1 : © leading zeros - days : when(s3=2 and d<10,"0","")&string(d)→d1 : © era format : when(y<0 and s4=4,"‾",""),when(y<0,when(s4=2," B.C.",when(s4=3," B.C.E.","")),when(s4=2," A.D.",when(s4=3," C.E.","")))}→e : © year : when(s1=4 or s1=8,right(string(y),2),string(y))→yr1 : © separators : when(s1=3 or s1=4 or s1>6,when(s2=1,{"-","-"},when(s2=2,{"/","/"},when(s2=3,{".","."},{" "," "}))),{" ",", "})→b : © put it all together : when(s1<5,m1&b[1]&d1,d1&b[1]&m1)&b[2]&e[1]&yr1&e[2] : EndFunc : Define setup(m,d,y)=Prgm : Local s1,s2,s3,s4 : Dialog : Title "Program Setup" : DropDown " Date "&when(d<10,when(m=9,"fmt",when(m>2 and m<8,"format","setup")),when(m=9,"",when(m>2 and m<9,"format",when(m=2 or m>10,"fmt","setup"))))&":",seq(dispdate(m,d,expr(y),{z,1,1,1}),z,1,8),s1 : DropDown " Date separator:",{"-","/","."," "},s2 : DropDown " Leading zeroes?",{"No","Yes"},s3 : DropDown " Era format:",{"None","B.C./A.D.","B.C.E./C.E.","‾"&y&"/"&y},s4 : EndDlog : when(ok=0,"",{s1,s2,s3,s4})→s : EndPrgm : {"ERROR: Year must be a number"," ERROR: There're only "," days in "}→err {" For negative years, use a minus sign (‾)."," Enter 'setup' for the year to edit settings. "," Month :"," Day :","Year "}→str : 0→quit : {1,1,1,1}→s : getDate()→j : j[2]→j1:j1→m2 : j[3]→j2:j2→d2 : string(j[1])→j3:j3→yr1:j3→yr2 : Loop : Loop : Dialog : Title "First date" : Text " Please enter the first date:" : DropDown str[3],marr,m1 : DropDown str[4],seq(string(z),z,1,31),d1 : Request str[5],yr1,0 : Text str[1] : Text "" : Text " For the second date... " : DropDown " ",{"Use today's date","Enter a date"},k : Text "" : Text str[2] : EndDlog : If ok=0 Then : 1→quit : Exit : EndIf : If yr1="setup" Then : setup(j1,j2,j3) : If s="" Then : 1→quit : Exit : EndIf : Cycle : EndIf : Try : iPart(expr(yr1))→yr1 : Else : ClrErr : Text err[1] : Cycle : EndTry : If getType(yr1)≠"NUM" Then : Text err[1] : Cycle : ElseIf d1>darr(m1,yr1) Then : Dialog : Text err[2]&string(darr(m1,yr1))&err[3] : Text " "&marr[m1]&"." : EndDlog : Cycle : EndIf : Exit : EndLoop : If quit=1 : Exit : If k=2 Then : Loop : Dialog : Title "Second date" : Text " First date:" : Text " "&dispdate(m1,d1,yr1,s) : Text "" : Text " Please enter the second date:" : DropDown str[3],marr,m2 : DropDown str[4],seq(string(z),z,1,31),d2 : Request str[5],yr2,0 : Text str[1] : Text "" : Text str[2] : EndDlog : If ok=0 Then : 1→quit : Exit : EndIf : If yr2="setup" Then : setup(j1,j2,j3) : If s="" Then : 1→quit : Exit : EndIf : Cycle : EndIf : Try : iPart(expr(yr2))→yr2 : Else : ClrErr : Text err[1] : Cycle : EndTry : If getType(yr2)≠"NUM" Then : Text err[1] : Cycle : ElseIf d2>darr(m2,yr2) Then : Dialog : Text err[2]&string(darr(m2,yr2))&err[3] : Text " "&marr[m1]&"." : EndDlog : Cycle : EndIf : Exit : EndLoop : Else : expr(j3)→yr2 : EndIf : If quit=1 : Exit : If yr1>yr2 or yr1=yr2 and m1>m2 or yr1=yr2 and m1=m2 and d1>d2 Then : yr1→a:yr2→yr1:a→yr2 : m1→a:m2→m1:a→m2 : d1→a:d2→d1:a→d2 : EndIf : darr(m1,yr1)-d1+d2→total : when(yr1=yr2,when(m1=m2,d2-d1,total+sum(seq(darr(a,yr1),a,m1+1,m2-1))),total+sum(seq(darr(a,yr1),a,m1+1,12))+sum(seq(darr(a,yr2),a,1,m2-1)))+when(yr1≠yr2,when(ceiling(yr1/10)=ceiling(yr2/10),sum(seq(yarr(a),a,yr1+1,yr2-1)),sum(seq(yarr(a),a,yr1+1,ceiling(yr1/10)×10))+sum(seq(yarr(a),a,ceiling(yr2/10)×10-10,yr2−1))+sum(seq(decarr(a×10+1),a,ceiling(yr1/10)+1,ceiling(yr2/10)-1))),0)→total : Dialog : Title "Total Days" : Text " There "&when(total≠1,"are ","is ")&string(total)&" day"&when(total≠1,"s","")&" between " : Text " "&dispdate(m1,d1,yr1,s)&" and" : Text " "&dispdate(m2,d2,yr2,s) : Text "" : Text " Press [ESC] to exit, or [ENTER] " : Text " to enter more dates." : EndDlog : If ok=0 : Exit : string(yr1)→yr1 : string(yr2)→yr2 : EndLoop : DelVar dispdate,s :EndPrgm
[edit] Functions
[edit] fliplist()
A simple function which takes a list and flips it. If a matrix is provided, it is converted to a list prior to flipping.
Uncompiled size | Compiled size | Dependancies |
---|---|---|
? bytes | ? bytes | None |
:fliplist(a) :mat|>list(seq(mid(a,dim(a)-b+1,1),b,1,dim(a)))|a=when(getType(a)≠"LIST",when(getType(a)="MAT",mat|>list(a),{a}),a)
[edit] gt()
A small wrapper function used between many of my other functions/programs and the built-in getType()
function. Note that this should only be used for determining the type of elements within an array, as replacing every instance of getType()
with gt()
and then compiling (running) the function or program will result in a compiled size larger than that of a getType()
version of the function or program. This probably also results in a (significant?) speed loss, but hasn't been tested to confirm it yet.
Uncompiled size | Compiled size | Dependancies |
---|---|---|
? bytes | ? bytes | None |
:gt(a) :getType(a)
[edit] isbn_grp()
A function which accepts an ISBN-10 or ISBN-13, with or without the check digit, and returns the base ISBN (9-digit number) split into the Group number and the rest of the number. If the group number is invalid, an error is returned instead.
Uncompiled size | Compiled size | Dependancies |
---|---|---|
725 bytes | 619 bytes | None |
:isbn_grp(a) :Func :when(getType(a)≠"STR",string(a),a)→a :Local b,c,d,e,f :dim(a)→b :For c,1,b : ord(mid(a,c,1))→d : when(d<48 or d>57,left(a,c-1)&right(a,dim(a)-c,a)→a : If dim(a)≠b Then : c-1→c : dim(a)→b : EndIf :EndFor :when(b=10,left(a,9),when(b=12 or b=13,mid(a,4,9),a))→a :If dim(a)≠9 : Return "Invalid ISBN size" :expr(left(a,1))→d :expr(mid(a,2,1))→e :expr(mid(a,3,1))→f :left(a,when(d=6,3,when(d=8,2,when(d=9,when(5≤e and e≤8,3,when(e=9,when(3≤f and f≤8,4,when(f=9,5,9)),2)),1))))→b :right(a,when(d=6,6,when(d=8,7,when(d=9,when(5≤e and e≤8,6,when(e=9,when(3≤f and f≤8,5,when(f=9,4,0)),7)),8))))→c :expr(b)→d :when(609<d and d<950 or 989<d and d<9934 or d=9969 or d=99900 or d=99907 or 99960<d,b&"-"&c&": Bad group #",{b,c}) :EndFunc
[edit] newarray()
A function that returns an array with the specified number of elements, pre-seeded with a given value. If a list is used for the number of elements, the list values are first multiplied to obtain the total number of elements. If the list is two elements in size, the function returns a matrix of the specified dimension.
Uncompiled size | Compiled size | Dependancies |
---|---|---|
? bytes | ? bytes | None |
:newarray(a,b) :seq(when(e="LIST" or e="MAT",when(c=2,seq(b,z,1,d[2]),b),b),z,1,when(e="LIST" or e="MAT",when(c=2,d[1],product(d)),d))|c=when(getType(a)="LIST",dim(a),when(getType(a)="MAT",dim(mat|>list(a)),1)) and d=when(getType(a)="MAT",mat|>list(a),a) and e=getType(a)