ralphb Posted December 12, 2015 Share Posted December 12, 2015 While pondering the problem of two different programs that would produce the same LIST output over in the Web99 thread, I thought that you may enjoy another programming challenge for a lazy weekend. (Sorry if this has been posted on AA before, as it's no new idea at all, but I couldn't find anything using the search function ...) Goal: Write a TI BASIC program that, when run, prints itself. In other words, LIST and RUN should produce exactly the same result. This kind of program is commonly called a quine. Here's my first entry (try it for yourself first, though): 1 READ A$ 2 PRINT "1 READ A$":A$:"3 DATA "&A$ 3 DATA 2 PRINT "1 READ A$":A$:"3 DATA "&A$ In some sense, it's the easy way out, as I'm using DATA. Can you come up with a different version, in particular one without DATA? BTW, if you want to feel really humbled just have a look at this quine or this quine. This guy is way, way beyond my league. (Coincidentally, his name handle is mame, but it's not related to MAME in any way.) 4 Quote Link to comment Share on other sites More sharing options...
Opry99er Posted December 12, 2015 Share Posted December 12, 2015 You know, I was struggling with this very problem not long ago when I was trying to write a tutorial in XB for my son. Very neat that it has a name!! 1 Quote Link to comment Share on other sites More sharing options...
+mizapf Posted December 12, 2015 Share Posted December 12, 2015 (edited) Recommended for reading: "Gödel, Escher, Bach: An Eternal Golden Braid". The author Douglas Hofstadter discusses the concept of Quines and demonstrates that by the very fact that a language which is expresive enough (i.e. which allows for writing any kind of program) always allows for creating Quines, and Quines can be used to prove incompleteness of the language, that every expressive language is necessarily incomplete (also Gödel's Incompleteness Theorem). Apart from that, a very interesting book that shows the interrelationship between mathematics, arts, and music. "Yields falsehood when preceded by its quotation" yields falsehood when preceded by its quotation. (Quine's paradox) Edited December 12, 2015 by mizapf 2 Quote Link to comment Share on other sites More sharing options...
ralphb Posted December 13, 2015 Author Share Posted December 13, 2015 There's a canonical solution without DATA that is fairly similar for all BASIC variants, but this morning I've had another idea that is actually unique to TI Extended BASIC. Load XB program QUINE from the attached disk image and see for yourself. Well, it satisfies my definition #2 above, so it is a quine. quine.dsk 3 Quote Link to comment Share on other sites More sharing options...
+mizapf Posted December 13, 2015 Share Posted December 13, 2015 When we ignore the * READY * line, of course. Quote Link to comment Share on other sites More sharing options...
Fredrik Öhrström Posted December 13, 2015 Share Posted December 13, 2015 (edited) I did not know that DATA could be fed unquoted strings where the quotes are plain. This makes your quine truly brilliant! The standard way is something like this, i suppose: 1 A$="1 A$=2 PRINT SEG$(A$,1,5)&CHR$(34)&SEG$(A$,1,99)&CHR$(34):SEG$(A$,6,99)" 2 PRINT SEG$(A$,1,5)&CHR$(34)&SEG$(A$,1,99)&CHR$(34):SEG$(A$,6,99) edit--- on the other hand i have no idea what the standard way is for basic, see here (spoilers for sure): https://www.nyx.net/~gthompso/self_bas.txt Edited December 13, 2015 by Fredrik Öhrström 1 Quote Link to comment Share on other sites More sharing options...
kl99 Posted December 15, 2015 Share Posted December 15, 2015 are we allowed to hide embedded assembler code in the memory? muhahahaha! Quote Link to comment Share on other sites More sharing options...
jrhodes Posted January 20 Share Posted January 20 (edited) On 12/13/2015 at 4:00 AM, ralphb said: There's a canonical solution without DATA that is fairly similar for all BASIC variants, but this morning I've had another idea that is actually unique to TI Extended BASIC. Load XB program QUINE from the attached disk image and see for yourself. Well, it satisfies my definition #2 above, so it is a quine. quine.dsk 90 kB · 81 downloads Thats neat! I actually had to look up how to un-protect a TI XB program to see what was going on 🙂. Spoiler CALL LOAD (-31931,0) Edited January 20 by jrhodes 1 Quote Link to comment Share on other sites More sharing options...
+TheBF Posted January 20 Share Posted January 20 ANS Forth shortest quine just for fun. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.