Stevan Apter wrote:
> thanks for asking ken.
>
> e:{$[(#b)=i:(|/'b:(w@[EMAIL PROTECTED]
(w:(`$" "\:x@[EMAIL PROTECTED]
in".?"))in`)in\:/:A)?1b;E@[EMAIL PROTECTED]
> " "~n:c@[EMAIL PROTECTED]
(c:{x@[EMAIL PROTECTED]
i)ss/:N;c
> .q.ssr[c;n;" "/:$(),P'(w[k],p:1_'(0,1+k:b[i]?1b)_`,w)"I"$n]]}
>
> it's just a single eye-watering case statement:
>
> if no keyword match in A, then return a default response from E
> else if no substitution in the response c picked from C, return c
> else substitute and return
This does so little that it should be no more than 2 lines.
In Ruby:
S =
[ /father|mother|brother|sister/i, "Tell me about your 0."],
[ /\b(am|i'm) (.*)/i, ["Why are you 2?","Have you always been 2?"]],
[ /\bI was (.*)/i, ["Why were you 1?","I can't believe you were
1."]],
[ /\bI will (.*)/i, "Do you think it's wise to 1?"],
[ /\bI (.*)/i, "Why do you 1?" ],
[ /\b(you|your|yours)\b/i, ["We're talking about you, not me.",
"Please don't be so personal."]],
[ /.*/, ["That's very interesting. Do go on.",
"Tell me more.",
"I'm not sure that I understand you fully.",
"Can you elaborate on that?" ]]
(gets;sub(/[.!?,; ]+$/,"");x=Array(S.find{|a|$m=$_.match(a[0])}[1])
puts x[rand(x.size)].gsub(/\d/){$m.to_a[$&.to_i]}) while 9
Although cryptic, it should make more sense to most programmers
than the K code.


|