Jump to content
ralphb

Quine challenge

Recommended Posts

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.)

 

  • Like 4

Share this post


Link to post
Share on other sites

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!!

  • Like 1

Share this post


Link to post
Share on other sites

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 by mizapf
  • Like 2

Share this post


Link to post
Share on other sites

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. :grin:

 

quine.dsk

  • Like 2

Share this post


Link to post
Share on other sites

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 by Fredrik Öhrström
  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...