Sunday, December 3, 2023

♞ Code challenge (BAM or your favourite BASIC): Create a simple quine

UPDATE 2023-12-10: Due to a family emergency today, I've had no time to properly "close" this challenge, so I'm extending this to December 17th.

NOTE: I've never done this kind of thing before and I do not know every BASIC out there.  So whatever I originally had in mind, this challenge is getting clarified/refactored a bit as questions come in, and as BASIC implementation-specific solutions (using fairly unique or unexpected features) roll in.   All in the hopes of clarity and making sure that you don't necessarily have too easy a time with the challenge !

From Wikipedia:

A quine is a computer program which takes no input and produces a copy of its own source code as its only output. The standard terms for these programs in the computability theory and computer science literature are "self-replicating programs", "self-reproducing programs", and "self-copying programs".

A story:

Back in the early 90's, our computer science "discrete structures" professor gave the class a bonus assignment: write a program that has no input and outputs itself such that the output can be run and that outputs the same result.  OR: write a proof that such a program cannot be created.

Do note: the program was required to have one or more variables, and the program had to completely contain itself.

Out of a class of about 60 students, only two of us completed the bonus assignment.  The other guy wrote a proof that such a program could not be written.  I wrote the program.

And we both got the same mark.  To this day, I'm still irritated that he got the same mark for a proof that I had totally invalidated.  Meh: I still think it was the coolest little program I've ever created.  Well, until this new version I just created a few hours ago, which inspired this code challenge.

 

The BASIC programming challenge:

With BAM or your favourite BASIC, code a program that has no input and, when run, creates output that exactly matches the program.

  • Printing to the screen is sufficient.
  • If your program has line numbers, the output must also have the line numbers
  • A solution specific to features and characteristics that aren't common/standard across all BASIC implementations is cool for that BASIC, but the best solutions will handle the greater problem of handling double-quotes with CHR$(34), or whatever ASCII code for double-quotes used for your BASIC
    • i.e. decently (if not completely) "cross-BASIC" solutions will be the best
    • "BASIC-specific" solutions are also cool
      • But let's be careful to not get into "this BASIC is better than some other BASIC(s)" silliness.
  • The only statements allowed: PRINT and LET
    • You can have as many PRINT statements as necessary
    • For variable assignments, if your BASIC requires LET (or you simply like using it), then by all means, you are allowed to use LET
  • The PRINT statement(s) must print one or more variables
  • The values assigned to the variables can only be the results of string expressions, limited to and having any combination of:
    • literal strings
    • other string variables
    • simple functions such as:
      • ASC
      • CHR$
      • SPACE$
      • LEFT$ / RIGHT$ / INSTR$ / REPLACE$
      • LEN
      • Any other function that can do nothing other than work with string literals or with string variables (putting literals in the variables, getting values from the variables)
  • The variables cannot be "system" variables; they must be end-user variables defined by the program.
The program must exclude:
  • "INCLUDE" directives!
  • BBC BASIC's "Page" variable (or equivalent in any BASIC); that variable gives the program code that is in whatever memory area, which is not the same as the program containing itself in a variable that the program sets with literals/variables and/or functions (limited to the ones allowed in this challenge).
  • Features/syntax that are not common across a large number of BASIC implementations.
    • If your program is very specific to your favourite BASIC implementation, that's cool and worth an honourable mention for sure.
    • Much better, though, if it is a program that can be run as-is on pretty much any BASIC out there (GW-BASIC, CBM BASIC, BBC BASIC, BASIC Anywhere Machine, SpecBAS, etc. etc. etc.)

Keep your code private/hidden until December 10th 17th !

Submit your solution (I'll be submitting mine too) anytime December 10th 17th !

Remember, the program must not have any input.  So no "LIST" statement (it uses input), no printing what is in memory (memory is input), no reading from a file.  In your program, you must hard-code the values that go into the variables.


No comments:

Post a Comment

🖥 Auto Biaxial Symmetry Graphing Personalizer

A little over a year ago, I created a an "Auto Biaxial Summetry" graphing program: Run the program View the source code I so enjoy...