XMLpitstop.com   |  VBnetexpert.com   |  Community Credit  
 
 
Pitstop Search:  
in
 
Sign in | Join | Help
 
 
  Blog
    Home  
 
  Entries By Date
 
<August 2008>
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456
 
 
  Blog Categories
   
 
  Archives
    December 2008 (1)  
    November 2008 (3)  
    September 2008 (3)  
    August 2008 (3)  
    June 2008 (4)  
    May 2008 (2)  
    April 2008 (3)  
    March 2008 (3)  
    February 2008 (5)  
    December 2007 (4)  
    November 2007 (1)  
    October 2007 (3)  
 
  Syndication
    RSS  
    Atom  
    Comments RSS  

Tuesday, August 12, 2008 - Posts

  .NET Flea Market  
 

Questions; Twenty of 'em

I was thinking of that interesting little pocket game, 20Q, where the game knows so many words and is able to figure out what word you're thinking of in 20 questions.  For the most part, it's not too bad.  It must really be pretty complex to be able to figure out all those words.

I've brainstormed on this idea before and whenever I start the code for it, I lose interest, but it doesn't stop me from kicking it around in my head over and over.

So pretty much, you have a database table full of answer words, which also has a numeric PK, you have a table of questions, with numeric PK, and you have a table with a matrix of every question and every answer PK and a response value (1=yes, 0=no).  That would be the basic data structure.  For data population, you could fill the answer table with random nouns pulled from any dictionary file.  That's simple.  For the questions table, you'd have to enter as many random questions as you could think of.  Random.  And LOTS.  Don't think of the answer, just think of any question.  Then after you've fried your mind with questions, do a Cartesian join to insert the PKs into the matrix table, leaving the response field null.  Now the fun part.  Make a form with big Yes and No buttons.  The form will read each row in the matrix table, joined with the question and answer table and you respond yes or no to each question/answer combination.  This should take a few days.

After sleeping off that headache and letting your eyes reset, it would be time to test coverage.  Do all of your questions provide a unique combination for every answer?  Does that get the wheels in your head spinning as to how to create such a uniqueness test?  I'm going to post my untested first idea, because nothing spurs responses better than posting something wrong.  My idea would be have an outer query (this is in .NET) for each answer PK, then an inner query that reads the question PK for each response that is yes (sorted by question PK, filtered by answer PK), loop through the inner query and concatenate the question PKs together into a big string and store it (maybe in a hashtable) with the answer ID as the value.  If you hit a dupe, then you have two answers that have the exact same yes responses.

After you've tested for full coverage and removed any answers that can't be exclusively answered by a series of responses, the goal is to present the most efficient question first.  What is the most efficient question?  The one that removes the most answers from the potential answer pool.  This is another fun mental exercise.  At the simplest level, it's the count of answers grouped by question filtered by all previous questions that don't match previous responses.  Something like (in pseudo-code)

select Questions.ID,count(Answers.ID) AnswerCount
from QAMatrix
join Answers on QAMatrix.AnswersID=Answers.ID
join Questions on QAMatrix.QuestionsID=Questions.ID
where Questions.ID=[previous question id] and QAMatrix.Response<>[previous response value]
and Questions.ID=[previous question id] and QAMatrix.Response<>[previous response value]
...
group by Questions.ID
order by 2 desc

I think that would do it.  The first question in the results should have the highest answers being trimmed out.  Looking at it now during a proofread, I suppose it might need enhanced so that it identifies the balance of yes/no responses in that count.  It won't do much good if 90% the answers were yes.  Well... depending on the answer, that's a potential risk with a potential huge reward - wiping out 90% of the possible answers.  Would an advanced 20Q program take more risks early or later or would it play middle-of-the-road and always shoot for a 50% split?  Design details for the interested.  Another 2nd version detail might be to remove any questions that don't split the answers well enough.  Maybe that's how 20Q ended up with such weird questions like "Does it grow hair?"

And that's about all the fun stuff I've been thinking about and not doing lately.

 
 
 

 
Copyright © . All Rights Reserved.
Powered by Community Server (Commercial Edition), by Telligent Systems