2
\$\begingroup\$

Quines have been around forever. It's a fun challenge: write a program that, when executed, generates its own source code as output. But how do you know it's actually producing its own source code? Generally, you have to look at it and compare it, but with quines generally being composed of tricky and intricate code, this is not always easy.

Comparing two strings, though, is something a computer does very well, so why not make the program validate itself? Your task is to create a program that:

  • produces its own source code as output
  • compares its output to its own source code
  • raises some sort of error, appropriate to the language used, if the output does not match
    • If the output does match, it's acceptable to terminate without further output
    • it can be hard-coded to know where to look to find its own source code for purposes of comparison. Using this knowledge to actually produce the output in the first place, however, is cheating.

Popularity contest; whoever gets the most upvotes wins. No standard loopholes, etc, you know the drill.

Enjoy!

\$\endgroup\$

closed as unclear what you're asking by a spaghetto, Geobits, mınxomaτ, Fongoid, Dennis Oct 6 '15 at 19:34

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 7
    \$\begingroup\$ I find this challenge confusing. If I understand correctly, I should write a source S for a program that produces output O such that O == S, and if O != S, then an error should be raised. But since O == S, I know that the output matches and no error should be raised, so the program doesn't need to check anything. \$\endgroup\$ – Zgarb Oct 6 '15 at 18:42
  • \$\begingroup\$ @Zgarb: But how do you know that O == S if you don't compare it? \$\endgroup\$ – Mason Wheeler Oct 6 '15 at 18:46
  • 6
    \$\begingroup\$ Because that's a necessary condition for being a valid answer. So if my answer is valid, I don't need to check the output. \$\endgroup\$ – Zgarb Oct 6 '15 at 18:52
  • 6
    \$\begingroup\$ @MasonWheeler You can create a quine in any language which is able to execute any code - also known as dynamic quine (or quine template). It's not difficult. || On a different note, you might want to include an example of what you expect in your task. \$\endgroup\$ – mınxomaτ Oct 6 '15 at 19:08
  • 9
    \$\begingroup\$ How do we validate the validation? That's the real question. \$\endgroup\$ – The_Basset_Hound Oct 6 '15 at 19:24