7
1
CleverBot is a conversational AI that works fundamentally by repeating responses from real humans it has heard previously. It starts off pretty dumb, but once the database becomes (a lot) larger it begins sounding more like an actual person!
How your program should work
- Output
Hi!
- Receive the user's reply as a string
- The reply is added to a list of responses associated with the program's last output (eg. the first reply would associate with
Hi!
).
- The reply is added to a list of responses associated with the program's last output (eg. the first reply would associate with
- Output one of the responses associated with the reply from step 2
- Every output has a list of responses associated with it.
- The response should be randomly selected from the list of associated responses.
- Matching of previous replies is case-insensitive and without symbols (only
0-9
,A-Z
and space are matched). For example, enteringhi
could return any response associated withhi
,Hi!
,///H|||I\\\
, etc. - If the user's reply does not match any previous responses, randomly select a response from the entire list of responses.
- Repeat steps 2 and 3 indefinitely
Rules
- Output must be exactly the same as the user originally entered it
- If a reply that needs to be added to the list of responses is already in the list, it can be optionally be added again (so it appears in the list twice)
- Input will never be empty and will only contain printable ASCII (code points
32
to126
) - All possible random values must have an equal chance of occurring
- Must be a full program (not just a function)
- Must output to
STDOUT
or closest equivalent - Must take input from
STDIN
or closest equivalent
Test Case
Hi!
> hi...
hi...
> HI
HI // could output "hi..." or "HI"
> How are you?
How are you? // could output "hi...", "HI" or "How are you?"
> Good.
Good. // could output "hi...", "HI", "How are you?" or "Good."
> ~!@#$*`'"(how ar%&e you_\|./<?
Good.
> Good.
~!@#$*`'"(how ar%&e you_\|./<? // could output "~!@#..." or "Good."
> 2Good.
HI // could output any of the user's previous replies
This is code-golf. Shortest answer in bytes wins!
Related. – Loovjo – 2016-01-16T09:23:05.213
Can there be two responses associated to one reply? – TanMath – 2016-01-16T11:00:25.763
@TanMath Yes, there can and should. Each reply has a list of responses. – user81655 – 2016-01-16T11:01:54.303