ralphb #1 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 Share this post Link to post Share on other sites
Opry99er #2 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 Share this post Link to post Share on other sites
mizapf #3 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 Share this post Link to post Share on other sites
ralphb #4 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 2 Quote Share this post Link to post Share on other sites
mizapf #5 Posted December 13, 2015 When we ignore the * READY * line, of course. Quote Share this post Link to post Share on other sites
Fredrik Öhrström #6 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 Share this post Link to post Share on other sites
kl99 #7 Posted December 15, 2015 are we allowed to hide embedded assembler code in the memory? muhahahaha! Quote Share this post Link to post Share on other sites