GPT can write Quines now (GPT-4)

GPT-4 is not only able to write code, more reliably than GPT-3.5, it writes code that writes code; see the example below (GPT-3.5 was not able to do this). But first, let me say:

1) @OpenAI: Thank for your openness to the world about your capabilities and shortcomings! Specifically, thanks for this:

2) Everyone else: many companies and projects will not be this open about their shortcomings and safety issues. Time to regulate, please!

Okay, here’s the example… GPT3.5 wasn’t able to do this, but GPT-4 nailed it on the first try:


Can you write me a python script that does the following three things?
1) When you run it with no argument, it prints “Hello world” to standard out.
2) When you run it with an argument “-s”, it prints its own source code.
As a constraint, I do not want the script to read or write to disk at all (so it can’t get its source code by just reading the file that it’s in).

Thanks if you can help with this! I’m curious to see how you do it.

BEGIN RESULT (works perfectly):

Sure! Here’s a Python script that should do what you’re looking for. This script uses a feature called quines, which are programs that can print their own source code:

import sys
def main():
source_code = 'import sys\n\ndef main():\n source_code = {!r}\n if len(sys.argv) > 1 and sys.argv[1] == "-s":\n print(source_code.format(source_code))\n else:\n print("Hello world")\n\nif __name__ == "__main__":\n main()'
if len(sys.argv) > 1 and sys.argv[1] == "-s":
print("Hello world")
if __name__ == "__main__":

When you run this script without any arguments, it will print “Hello world”. When you run it with the “-s” argument, it will print its own source code without reading or writing to disk.


I’m not sure how hard they tried specifically to train this, but it’s worth knowing about for lots of reasons I probably don’t have to explain at length right here.