28
3
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.
Background
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:
Yes
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:
a dog
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
no
And it would say
Thanks
Next time it runs, it would ask the question above, and would build up a binary tree of such questions.
The challenge
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 toSTDOUT
. No answer written in a language that does not support writing toSTDOUT
andSTDERR
or reading fromSTDIN
will be valid.In other words under UNIX you could invoke the program like this:
example:
$ 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:
list:
"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
y
oryes
in any case for 'yes', andn
orno
in 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 withy
orY
as '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
STDIN
,STDOUT
, andSTDERR
), 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
STDOUT
exactly 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
STDOUT
in 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
STDIN
andSTDERR
dialog).Standard loopholes are excluded.
Should the program be able to mutate multiple times and support more than 2 animals? If so, can you provide an example "Please give me a question about ..." dialogue when there are already two or more animals the program knows about? – Cristian Lupascu – 2015-09-07T07:24:57.647
What if the user only says "dog" instead of "a dog"? Shall we parse the sentence to detect "a/an" or can we treat the answer literally? I assume so given the prompts you gave (%s). – coredump – 2015-09-07T08:45:42.747
@w0lf yes, you need to cope with multiple rounds. There are examples of multi-round games here: https://studentnet.cs.manchester.ac.uk/ugt/COMP26120/lab/ex9game.html - I will fix the documentation.
– abligh – 2015-09-07T08:54:20.3071@coredump if the user says "dog" not "a dog", then the replies will not be grammatical. That's not an issue. – abligh – 2015-09-07T08:55:23.800
1Oof. Trying to do this in Runic would be a nightmare. The primary reason being that wiring up all the bits to cope with arbitrary input strings (which then need to be present as string literals in the resulting output program) would be basically impossible. Oh and Runic can't output to STDERR. – Draco18s no longer trusts SE – 2019-06-23T21:38:25.203
1
This seemed like a fun "game", so rather than golf it, I made a codepen where you can play the Pangolin Game to your heart's content. Enjoy!
– Skidsdev – 2019-06-26T20:11:18.717