- The Smallest BF interpreter in TI-Basic
- 21 Feb 2019 01:27:48 pm
- Last edited by LogicalJoe on 27 Feb 2019 05:10:53 pm; edited 6 times in total
So mid-January (Jan 9, 2019), I realized that squishy's BF interpreter is way oversized, so I began to make my own in TI-Basic.
My initial version was quite bloated at 274 bytes, but it worked (as a proof of concept):
Code:
[The new-lines are for TI's on-calc editor which is the only thing I have worked on this in.]
My subsequent version was 232 bytes, then 200, 194, 185, 178, 176, 173, 171, then finally, 169 bytes.
I reached 169 Feb 19, 2019, and I believe this to be a lower minimum (but that's what I thought of 176 and 171 too ).
Some limitations came into play though.
Code:
I will post my smallest later (maybe it will be even better then) so that you guys can puzzle over how to make one yourselves (It is the best way to learn!).
If someone (anyone) can beat my 169, I will be amazed and will post my code asap.
Timing: I measure the speed of the interpreter by running "+[.+]":prgmBLANK for 2-10 minutes and dividing the number of seconds by whatever number it ended on (my 169 byte is 2.1083 numbers/sec which is not my best.)
[.+] is equivalent to:
Code:
in BASIC.
If you have any questions or you think you can make a smaller interpreter, please post below.
Post your smallest BF Interpreter here so we can see how you did (after you make it)…
EDIT: If you don't know what BF is, you can read the wiki on it here: https://en.wikipedia.org/wiki/Brainf--k
Current Results:
LogicalJoe: 145 (derived from lirtosiast's solution)
lirtosiast: 146
PT_: 159
LogicalJoe: 163
kg583: 165
JWinslow23: 167
My initial version was quite bloated at 274 bytes, but it worked (as a proof of concept):
Code:
Ans→Str1
DelVar L₁999→dim(L₁:1→A
1→B:While A≤length(Str1
sub(Str1,A,1→Str2
B+(Str2=">")-(Str2="<→B
L₁(B)+(Str2="+")-(Str2="-→L₁(B
If Str2=".
Disp L₁(B:If Str2=",
Then:Input C:C→L₁(B:End
1→C:If Str2="]
Then:If 0≠L₁(B:Then
Repeat C=0:A-1→A
sub(Str1,A,1→Str2
C+(Str2="]")-(Str2="[→C
End:End:Else:If Str2="[
Then:If not(L₁(B:Then
Repeat C=0:A+1→A
sub(Str1,A,1→Str2
C+(Str2="[")-(Str2="]→C
End:End:End:End:A+1→A:End
[The new-lines are for TI's on-calc editor which is the only thing I have worked on this in.]
My subsequent version was 232 bytes, then 200, 194, 185, 178, 176, 173, 171, then finally, 169 bytes.
I reached 169 Feb 19, 2019, and I believe this to be a lower minimum (but that's what I thought of 176 and 171 too ).
Some limitations came into play though.
Code:
restricted tokens: prgm
as few variables as possible. (I am using 6, counting lists, variables, and strings (not ans))
I will post my smallest later (maybe it will be even better then) so that you guys can puzzle over how to make one yourselves (It is the best way to learn!).
If someone (anyone) can beat my 169, I will be amazed and will post my code asap.
Timing: I measure the speed of the interpreter by running "+[.+]":prgmBLANK for 2-10 minutes and dividing the number of seconds by whatever number it ended on (my 169 byte is 2.1083 numbers/sec which is not my best.)
[.+] is equivalent to:
Code:
While Ans:Disp Ans:Ans+1:End
If you have any questions or you think you can make a smaller interpreter, please post below.
Post your smallest BF Interpreter here so we can see how you did (after you make it)…
EDIT: If you don't know what BF is, you can read the wiki on it here: https://en.wikipedia.org/wiki/Brainf--k
Current Results:
LogicalJoe: 145 (derived from lirtosiast's solution)
lirtosiast: 146
PT_: 159
LogicalJoe: 163
kg583: 165
JWinslow23: 167