Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: calcdude84se on January 10, 2011, 09:59:15 pm

Title: BASIC One-Liners
Post by: calcdude84se on January 10, 2011, 09:59:15 pm
Post your favorite useful (or useless) one-line snippets of TI-BASIC code here! :D
I'll start us off with a few of my favorites, list operations:
Code: ("Total Occurences") [Select]
"Returns how many times Ans is an element in L1
sum(Ans=L1
Code: ("Single-Occurrence index") [Select]
"Finds where Ans is in L1 provided it only occurs once
1+dim(L1)-sum(cumSum(L1=Ans
Code: ("Occurrence index") [Select]
"Finds the index of the Xth occurrence of Ans in L1 (indexed from 1)
1+dim(L1)-sum(X<=cumSum(L1=Ans
Title: Re: BASIC One-Liners
Post by: SirCmpwn on January 10, 2011, 10:00:55 pm
Shortest (and hardest) game ever:
Code: [Select]
Disp "The Game"
Title: Re: BASIC One-Liners
Post by: Masinini on January 10, 2011, 10:02:47 pm
Lbl 99.

Story is, I used to use number lbl's only, and before I knew how to optimize and about sub routines, I had a program that used 99 lbl's.
Title: Re: BASIC One-Liners
Post by: calcdude84se on January 10, 2011, 10:03:08 pm
Also, before someone does it, no ':'s except as part of a string ;D
Sir, that can be optimized to
Code: [Select]
Disp "The Game:P
Title: Re: BASIC One-Liners
Post by: DJ Omnimaga on January 10, 2011, 10:15:17 pm
Also, before someone does it, no ':'s except as part of a string ;D
Aw... I was gonna post xLIB xLIB Revolution source code ;D
Title: Re: BASIC One-Liners
Post by: Runer112 on January 10, 2011, 10:26:17 pm
Code: [Select]
:prgmXXR
Title: Re: BASIC One-Liners
Post by: DJ Omnimaga on January 10, 2011, 10:32:43 pm
Lol Runer112. Finally it seems XXR isn't one single line, though. I thought it did because it barely used any text and the menu texts were sprites.

On an off-topic note I remember these days O.O

(http://www.omnimaga.org/images/screenshots/xxrstats.gif)

(http://www.omnimaga.org/images/screenshots/xxrstats2.gif)

That was after XXR made Engadget front page, though (along with plenty of other blogs including Japanese ones). Still, I think that was the only time where a program beat VTI, Mario and MirageOS at once O.O
Title: Re: BASIC One-Liners
Post by: sjasogun1 on January 13, 2011, 04:14:37 am
Not really a one-liner, but still pretty small game written on my fx-9860 GII (yes on the calc itself, using the program function, not very efficiënt but whatever):

Spoiler For Spoiler:
“PRESS ANY NUMBER AND THEN EXE TO BEGIN”
? --> A
CLRTEXT
RAN# --> A
LOCATE 1,2,A
IF A<0.9
THEN LOCATE 12,2,”<0.9”
LOCATE 1,3,”SUCCESS!”
LOCATE 1,4,”LEVEL 1 COMPLETE”
LOCATE 1,5,”PRESS ANY NUMBER AND”
LOCATE 1,6,”THEN EXE TO CONTINUE”
? --> A
CLRTEXT
RAN# --> B
LOCATE 1,2,B
IF B<0.75
THEN LOCATE 12,2,”<0.75”
LOCATE 1,3,”SUCCESS!”
LOCATE 1,4,”LEVEL 2 COMPLETE”
LOCATE 1,5,”PRESS ANY NUMBER AND”
LOCATE 1,6,”THEN EXE TO CONTINUE”
? --> A
CLRTEXT
RAN# --> C
LOCATE 1,2,C
IF C<0.45
THEN LOCATE 12,2,”<0.45”
LOCATE 1,3,”SUCCESS!”
LOCATE 1,4,”LEVEL 3 COMPLETE”
LOCATE 1,5,”PRESS ANY NUMBER AND”
LOCATE 1,6,”THEN EXE TO CONTINUE”
? --> A
CLRTEXT
RAN# --> D
LOCATE 1,2,D
IF D<0.2
THEN LOCATE 12,2,”<0.2”
LOCATE 1,3,”SUCCESS!”
LOCATE 1,4,”LEVEL 4 COMPLETE”
LOCATE 1,5,”PRESS ANY NUMBER AND”
LOCATE 1,6,“THEN EXE TO CONTINUE”
? --> A
CLRTEXT
RAN# --> E
LOCATE 1,2,E
IF E<0.05
THEN LOCATE 12,2,”<0.05”
LOCATE 1,3,”SUCCESS!”
LOCATE 1,4,”LEVEL 5 COMPLETE”
LOCATE 1,5,”YOU WON! CONGRATULATIONS!”
LOCATE 1,6,”PRESS ANY KEY TO FINISH”
ELSE LOCATE 12,2,”>0.05”
LOCATE 1,3,”FAIL…”
IFEND
ELSE LOCATE 12,2,”>0.2”
LOCATE 1,3,”FAIL…”
IFEND
ELSE LOCATE 12,2,”>0.45”
LOCATE 1,3,”FAIL…”
IFEND
ELSE LOCATE 12,2,”>0.75”
LOCATE 1,3,”FAIL…”
IFEND
ELSE LOCATE 12,2,”>0.9”
LOCATE 1,3,”FAIL…”
IFEND