This is a code-golf challenge whereby you need to devise a program that acts like a quine or a quine that modifies itself to illustrate machine learning.
There is a basic artificial intelligence program called 'the pangolin game' which is described here. The basic ideas is that the program when run the first time asks:
OK, please think of something
Is it a pangolin?
You may then reply either:
In which case it says:
Good. That was soooo easy.
Or if not it says:
Oh. Well you win then -- What were you thinking of?
To which you might say:
To which it would say
Please give me a question about a dog, so I can tell the difference between a dog and a pangolin
you might reply
Does it eat ants?
It would then ask:
What is the answer for a dog?
To which you would say
And it would say
Next time it runs, it would ask the question above, and would build up a binary tree of such questions.
Enough of the background. This challenge is to write a self modifying pangolin program. The rules are as follows:
Program output (as described above) should be to
STDERR. The final response will always be "Good. That was soooo easy." or "Thanks". After this, it should output either the current version of the program, or a new version of the program that incorporates the question to
STDOUT. No answer written in a language that does not support writing to
STDERRor reading from
STDINwill be valid.
In other words under UNIX you could invoke the program like this:
$ mylanguage myprogram > myprogram.1 [dialog goes here] $ mylanguage myprogram1 > myprogram.2 [dialog goes here]
- The program has to use exactly the specified prompts (because shortening the prompts shows no skill). The prompts are (without the quotes, and where %s is substituted) as follows:
"OK, please think of something" "Is it %s?" "Good. That was soooo easy." "Oh. Well you win then -- What were you thinking of?" "Please give me a question about %s, so I can tell the difference between %s and %s" "What is the answer for %s?" "Thanks"
When expecting yes/no answers, your program should accept
yesin any case for 'yes', and
noin any case for 'no'. What you do with non-conforming inputs is up to you. For instance you might decide to take any answer that begins with
Yas 'yes', and anything else as no.
You may assume that the names of the things supplied and the questions consist only ASCII letters, numbers, spaces, hyphens, question marks, commas, full stops, colons, and semicolons, i.e. they match following regex
^[-?,.;: a-zA-Z]+$. If you can cope with more than that (especially the quoting characters in your chosen language) you get to be smug, but don't gain any extra points.
Your program may not read or write any file (excluding
STDERR), or from the network; specifically it may neither read nor write its own code from disk. Its state must be saved in the program code itself.
When the program is run and guesses the answer correctly, it must perform exactly as a quine, i.e. it must write to
STDOUTexactly its own code, unchanged.
When the program is run and guesses the answer incorrectly, it must encode the provided new question and answer within its own code and write it to
STDOUTin its own code, so it is capable of distinguishing between its original guess and the provided new object, in addition to distinguishing between all previously given objects.
You must be able to cope with multiple sequential runs of the software so it learns about many objects. See here for examples of multiple runs.
Test runs are given at the link in the head (obviously covering only the
Standard loopholes are excluded.