I'm sure all of us have some code that we have written that we are especially proud of (such as a game or short routine). Post your favorite code below, and the reasons why you like it so much. Please use the appropriate tokens from the CHAR box in the top-right corner and post the code in a [[code]]…[[/code]] or [[span class="werecode"]]…[[/span]] block.

Well, I am *proud* of many codes I have written; it is hard to pick out just *one*. One I was really proud of a while ago when I first wrote it (I have only been programming for a few months) was the code I cake up with for clicking in my prototype Scope program. It is pretty pathetic, but when I first wrote it, it was amazing!

```
0->A
0->B
0->C
26->X
26->Z
While 1
If A[does not equal sign]0 or B[does not equal sign]0
Pt-Off(X,Z,2
getkey->K
A+(K=26)-(K=24)->A
B+(K=25)-(K=34)->B
X+A->X
Z+B->B
Pt-On(X,Z,2
If X>94:-1->A
If X<0:1->A
If Z>62:-1->B
If Z<0:1->B
If X>___ and X<___ and Z>___ and Z<___ and K=21
1->C
If C=1:Then
[...]:End
End
```

There was more to it, but *that* was the idea of it. :D

Coffee + Radiohead = ^^

Oh, there are several.

Yahtzee scorer:

:sum(L1=median(L1→X

:max(not(fPart(prod(2L1+1-7(L1=4))/{210,770,2002

:Ans+6not(AnsfPart(2variance(L1

:If X=3

:2+(2=sum(L1=max(L1not(L1=median(L1

:If X>3

:X

:sub("S3H4YCL",Ans,1

3 = Three-of-a-kind

4 = Four-of-a-kind

H = Full house

S = Small straight

L = Large straight

Y = Yahtzee

C = Chance

An X in the range [8,120] can be taken as prime if gcd(X,35)=not(min(fPart((X+{1,-1})/6.

The vertex of a parabola ax²+bx+c can be reformulated as the complex number C*i*-B/A/4(B*i*+2).

This post concerns solutions of linear (in)equalities in one variable.

If I feel up to it, I'll re-undertake optimizations on a routine that scans products of up to 26 distinct, integer-exponentiated variables like these and answers them with their reduced forms, along the lines of (a^{22}p^{13}v^{3}y^{19})/(k^{20}n^{15}r^{1}) – it's my favorite code that hasn't been posted anywhere yet.

My favorite piece of TI-Basic code that I've written is the Tic Tac To game. If I remember correctly, I think I even got some help from Weregoose optimizing it :D

:0→A:0identity(3→[A]

:1-2int(2rand→B

:"+++

:ClrHome

:Disp Ans,Ans,Ans

:Repeat 0

:Repeat Ans

:.1getKey→K

:End

:If 2Ans=9:Goto Q

:iPart(Ans)-6→C

:10fPart(K)-1

:If max(2≤abs({C,Ans}-2:End

:If [A](C,Ans:End

:Output(C,Ans,sub("X O",B+2,1

:B→[A](C,Ans

:For(C,0,1

:[A]T→[A]

:For(D,1,3

:Matr►list([A],D,T

:If min(∟T=B:Goto Q

:End

:If min(B=seq([A](abs(4C-X),X),X,1,3

:Goto Q

:End

:-B→B:IS>(A,9

:End

:Lbl Q

:"TIE!

:If A≠9

:sub("X O",B+2,1)+" WINS!

:If 2K≠9

:Pause Ans

:ClrHome:"

That is really awesome o.o I know that for a long time I used something similar to the first part of that code:

```
:0identity(3→[A]
:ClrHome
:"***
:Disp Ans,Ans,Ans
```

However, I also notice that your program can be optimised further, at least for speed. Think about it: when a piece is placed and there were no wins before, then in order for a win to happen on this turn, it has to occur either on a diagonal or in the row or column that the piece was placed. I honestly didn't think about that for about two or three years of making a Tic-Tac-Toe at every big math test. When I realised this, all I could do was laugh at myself. Since then, I have always remembered that trick when making a game. Anyways:

```
:Matr►list([A],D,T
:If min(∟T=B
:Goto Q
:Matr►list([A]T,C,T
:If min(∟T=B) or min(B=seq([A](4-X,X),X,1,3)) or min(B=seq([A](X,X),X,1,3
:Goto Q
:End
```

**EDIT:**More optimised, I think:

```
:Matr►list([A],D,T
:min(∟T=B
:Matr►list([A]T,C,T
:If Ans or min(∟T=B) or min(B=seq([A](4-X,X),X,1,3)) or min(B=seq([A](X,X),X,1,3
:Goto Q
:End
```

Z80 Assembly>English>TI-BASIC>Python>French>C>0

You're right, that is a good optimization for speed… I don't think speed is really an issue in the program, however, so size is the more important concern.

I'm curious, why do you make a tic-tac-to game at every big math test?

It was kind of a ritual. It started in tenth grade when I first got my hands on a calculator. I finished the state exam in about an hour and it was mandatory that we stay for at least 1.5 hours. I decided to make Tic-Tac-Toe and it worked. Then I did the same at the next exam, but I added AI, too. Then I started getting better at programming *and* math. I retook the hardest highschool state math exam every semester just to have a math exam to continue the ritual. I ended up completing it the last time without once using my calculator in a half hour (I computed things like sine and cosine manually using calculus — it helps that I can do math pretty quickly on paper and I knew a bunch of tricks and shortcuts). After I finished, I had one hour, so I made the tic-tac-toe program with AI support for either player, AI v. AI, and Player v. Player and I started on Connect 4, but never finished it :/

Z80 Assembly>English>TI-BASIC>Python>French>C>0

I think the code I'm most fond of is my basic-mapmaker utility. It used F1-F5 for hot menus (F1-F3 were the character lists, and F4 and F5 were options and help), and it had hotkeys that were bindable to special characters. You could toggle Alpha, second, and lowercase and type normally, too.

It's still sitting on my calculator as a group, and I've been waiting for a chance to get it off of there.

Hmmm….I dunno…

Maybe Linux…even though it's not done yet XD

I'm also pretty proud of my Physics program…

I have a WIP called CHATBOT. Check it out once I post the code!

```
:ClrHome:Disp "HOW DOES A","MATHEMATICIAN","LOSE WEIGHT?
:Pause "
:Pause "BINOMIALS!
:Pause "(BUY NO MEALS)":ClrHome
```

Clicking with the DCS lib:

```
:{1,1,0→L₁
:Repeat 19>abs(46-L₁(1)) and 12>abs(43-L₁(2
:L₁
:Repeat 1=Ans(3
:sum(6,Ans(1),Ans(2 //not sum() command - sum(6 is the command and Ans(1) and Ans(2) are the arguments for this mouse lib
:End
:Ans→L₁
:End
:2iPart(8¹(L₁(2)-31 // that's 8 inv
:Ans+(46<L₁(1→C
```

And C was a number, 1-6! I was quite proud when I thought of using the distance from the center of the clickable item…

That looks nice… What program did you create that for?

It was a menu for all my DCS games. I think I made a MEMPI game, a JUMP game, and a FALLDWN game, though I can only find MEMPI and JUMP and they all used tokens that my 2.43 downgrade can't read - they cause crashes upon running. This was right before I decided to start learning Axe the second time (I gave up originally) and it was my last "great" optimization.

My favorite code is probably the one for this program which I'm still currently working on (ie. the AI or Instructions don't function). That code is way too long to post, but my favorite part of it is probably the animation for selecting a square:

function performSelection(e:Event):void{ addEventListener("mouseOut",removeSelection); for(var i:int; i <= 22; i++){ var initialY:Number = Math.floor(Math.random()*6-6); var particle:SelectParticle = new SelectParticle(); this.addChild(particle); if(i <= 12) particle.x = Math.floor(Math.random()*20+20); else if(i >= 13 && i <= 18) particle.x = Math.floor(Math.random()*20+10); else particle.x = Math.floor(Math.random()*25-5); particle.y = -3; particle.alpha = 0; } } function removeSelection(e:Event):void{ removeEventListener("mouseOut",removeSelection); for(var i:int = 2; i < numChildren; i++){ var child = getChildAt(i); child.addEventListener("enterFrame",child.removeAlpha); } }

My favorite TI-Basic code is probably the following. It is a segment of a radical simplifier I made a long time ago; this segment supposedly searches for situations like $\sqrt[4]{36} = \sqrt[4]{6^2} = \sqrt{6}$. C is the index, and B is the radicand.

C

Repeat Ans=1

C/Ans+1

While fPart(C/Ans

Ans+1

End

C/Ans→L

If Ans=1

Goto 0

If not(fPart(round(Ans^{x}√B

Then

C/Ans→C

L^{x}√B→B:C

End

Lbl 0

End

Timothy Foster - @tfAuroratide

Auroratide.com - Go here if you're nerdy like me

I think my favorite code that I've written is by far my 977 byte version of the classic arcade game Snake. This is the final version, v.14.0:

```
PROGRAM:SNAKE
:AxesOff
:GridOff
:FnOff
:PlotsOff
:ZStandard
:ZInteger
:SetUpEditor ⌊SNAKE
:SetUpEditor
:"HIT ENTER→Str1
:Text(-1,1,1,"SNAKE-84
:Text(8,1,"WOLFGANG47
:Text(57,1,"V.14.0
:Text(18,1,"MOVE: ARROWS
:Text(26,1,"PAUSE: 2ND
:Text(34,1,"QUIT: 2ND MODE
:Text(57,62,Str1
:Pause
:Lbl M
:ClrDraw
:30→dim(⌊SNAKE
:Menu("SNAKE","START",1,"SCORES",0,"QUIT",Q
:Lbl 0
:Text(-1,1,1,"HIGHSCORES
:DelVar C
:For(A,1,82,16
:For(B,11,43,8
:C+1→C
:⌊SNAKE(Ans
:Text(B,A,Ans
:If Ans≤99
:Text(B,A,0,Ans
:If Ans≤9
:Text(B,A,0,0,Ans
:End
:End
:mean(⌊SNAKE
:Text(57,1,"AVG ",round(ans,0 //two (2) spaces after AVG
:Text(57,62,Str1
:Pause
:Goto M
:Lbl 1
:ClrList L₁
:405→dim(L₁
:L₁→L₂
:For(A,41,Xmax
:Vertical A
:Vertical -A
:End
:For(A,-32,-26
:Horizontal -A
:Horizontal 6+A
:Line(Xmin,A,Xmax,A,0
:End
:Text(57,0,"SCORE
:DelVar A3→B
:DelVar C3→D
:0→PV:0→FV
:0→I%:1→P/Y
:3→PMT
:Pt-On(A,B,3
:Repeat ℕ=22 or I%
:Repeat ℕ=-4 or I%
:Repeat ℕ+I%
:PV+C→PV
:FV+D→FV
:pxl-Test(30-FV,46+PV→I%
:Pt-On(PV,FV,2
:If A=PV and B=FV:Then
:Pt-Off(A,B
:Repeat not(A=L₁(C/Y) and B=L₂(C/Y) or pxl-Test(30-B,46+A
:3randInt(-13,13→A
:3randInt(-6,8→B
:End
:Pt-On(A,B,3
:PMT+1→PMT
:Text(57,25,Ans-4
:End
:P/Y+1-P/Y(P/Y>404→P/Y
:P/Y-PMT+405(P/Y-PMT<1→C/Y
:Pt-Off(L₁(C/Y),L₂(C/Y),2
:PV→L₁(P/Y
:FV→L₂(P/Y
:getKey→ℕ
:End
:ℕ-25→ℕ //First line of Weregoose's optimized code
:Ans=9
:If Ans or 2>abs(ℕ:Then
:not(ℕ)-Ans
:If CAns
:DelVar C3Ans→D
:If Dnot(Ans
:DelVar D3ℕ→C
:End //Final line of Weregoose's optimized code
:End
:If not(I%:Then
:Pt-On(PV,FV
:Text(57,76,"Pause //Use the "Pause " token
:Repeat max(ℕ={21,22
:getKey→ℕ
:End
:For(E,76,93
:Text(57,E," //One (1) space
:End
:Pt-Off(PV,FV
:End
:End
:PMT-4→⌊SNAKE(31
:SortD(⌊SNAKE
:If ℕ=22 or not(I%
:Goto Q
:Text(57,62,Str1
:Pause
:Goto M
:Lbl Q
:ClrList L₁,L₂
:DelVar Str1
:ZStandard
:AxesOn
:prgmθDELVAR
```

And here is the subprogram at the end:

```
PROGRAM:θDELVAR
:DelVar ADelVar BDelVar CDelVar DDelVar EDelVar FDelVar GDelVar HDelVar IDelVar JDelVar KDelVar LDelVar MDelVar NDelVar ODelVar PDelVar QDelVar RDelVar SDelVar TDelVar UDelVar VDelVar WDelVar XDelVar YDelVar ZDelVar θClrHome
```

I tried to type this up with completely accuracy, but obviously, everyone makes mistakes, so if you believe you see any errors or typos, please let me know.

Just keep in mind that PV, FV, P/Y, C/Y, ℕ, I%, PMT are ALL FINANCE VARIABLES.

There is a small but important section of code that was optimized by Weregoose. These lines are indicated in the code block.

If anyone wants to try out this code, and compare high scores, my high score is 95, and my average score on the high score table is 60.

Just a heads up, this is a REALLY fast version of Snake, especially if you are using a TI-84 SE (or TI-84+). However, if you are using a TI-83+ or earlier model of calculator, I don't really recommend playing this version of Snake, because it will slow down dramatically on an older calculator.

—Wolfgang

My personal favorite is this code that outputs a command on the keyboard from a key-press between K=51 and K=105 inclusive.

```
"-1sin(cos(tan(^²,()/log(789*ln(456- 123+ 0.‾"→Str3 // with spaces before the 1 and the 0
Text(A,B,sub(Str3,K-50-(10int(K/10)-50)/2,1
```

I used it so that I could type on the graph-screen.