'=========================================================================== ' Subject: SEVEN QUESTIONS WITH LIES Date: 08-06-97 (10:33) ' Author: James Rioux Code: QB, QBasic, PDS ' Origin: bshadow@nbnet.nb.com Packet: AI.ABC '=========================================================================== ' Seven Questions with Lies ' by James Rioux ' About LIES ' ' This program is based upon a neat mathematical concept called an error- ' correcting code. It asks you questions about a number you mentally ' select, and then tells you what your number is. Here's the neat part: ' you can lie on one of the questions, and the computer can still tell you ' what your number is. Unless you lie on more than 1 question, the computer ' almost always gets the right answer. CLS LOCATE 2, 30 PRINT "Seven Questions with Lies" LOCATE 5 PRINT "Pick a number between 1 and 15, inclusive. I will ask you seven questions" PRINT "about the number to try to determine what it is. You may lie on one question," PRINT "and I'll still get it right every time if you follow my instructions. Answer" PRINT "Y or N when asked a question." PRINT "" PRINT "Once you have the number, press any key to continue." DO LOOP UNTIL INKEY$ <> "" CLS 2 LOCATE 2 INPUT "Is your number in this set: {1, 3, 4, 6, 8, 10, 13, 15} ? ", ANSWER1$ ANSWER1$ = UCASE$(ANSWER1$) IF ANSWER1$ = "Y" THEN GOTO 3 IF ANSWER1$ = "N" THEN GOTO 3 ELSE GOTO 2 3 LOCATE 4 INPUT "Is your number in this set: {1, 2, 5, 6, 8, 11, 12, 15} ? ", ANSWER2$ ANSWER2$ = UCASE$(ANSWER2$) IF ANSWER2$ = "Y" THEN GOTO 4 IF ANSWER2$ = "N" THEN GOTO 4 ELSE GOTO 3 4 LOCATE 6 INPUT "Is your number in this set: {1, 2, 4, 7, 9, 10, 12, 15} ? ", ANSWER3$ ANSWER3$ = UCASE$(ANSWER3$) IF ANSWER3$ = "Y" THEN GOTO 5 IF ANSWER3$ = "N" THEN GOTO 5 ELSE GOTO 4 5 LOCATE 8 INPUT "Is your number in this set: {8, 9, 10, 11, 12, 13, 14, 15} ? ", ANSWER4$ ANSWER4$ = UCASE$(ANSWER4$) IF ANSWER4$ = "Y" THEN GOTO 6 IF ANSWER4$ = "N" THEN GOTO 6 ELSE GOTO 5 6 LOCATE 10 INPUT "Is your number in this set: {4, 5, 6, 7, 12, 13, 14, 15} ? ", ANSWER5$ ANSWER5$ = UCASE$(ANSWER5$) IF ANSWER5$ = "Y" THEN GOTO 7 IF ANSWER5$ = "N" THEN GOTO 7 ELSE GOTO 6 7 LOCATE 12 INPUT "Is your number in this set: {2, 3, 6, 7, 10, 11, 14, 15} ? ", ANSWER6$ ANSWER6$ = UCASE$(ANSWER6$) IF ANSWER6$ = "Y" THEN GOTO 8 IF ANSWER6$ = "N" THEN GOTO 8 ELSE GOTO 7 8 LOCATE 14 INPUT "Is your number in this set: {1, 3, 5, 7, 9, 11, 13, 15} ? ", ANSWER7$ ANSWER7$ = UCASE$(ANSWER7$) IF ANSWER7$ = "Y" THEN GOTO 9 IF ANSWER7$ = "N" THEN GOTO 9 ELSE GOTO 8 ' These definitions are to set up the arithmetic involved in the error ' correcting code - to determine if you lied on a question 9 Set1 = 100 Set2 = 10 Set3 = 1 Set4 = 110 Set5 = 101 Set6 = 11 Set7 = 111 A = 0 B = 0 C = 0 IF ANSWER1$ = "Y" THEN A = A + 1 IF ANSWER2$ = "Y" THEN B = B + 1 IF ANSWER3$ = "Y" THEN C = C + 1 IF ANSWER4$ = "Y" THEN A = A + 1: B = B + 1 IF ANSWER5$ = "Y" THEN A = A + 1: C = C + 1 IF ANSWER6$ = "Y" THEN B = B + 1: C = C + 1 IF ANSWER7$ = "Y" THEN A = A + 1: B = B + 1: C = C + 1 ' This is MOD 2 arithmetic IF A / 2 = INT(A / 2) THEN A2 = 0 ELSE A2 = 100 IF B / 2 = INT(B / 2) THEN B2 = 0 ELSE B2 = 10 IF C / 2 = INT(C / 2) THEN C2 = 0 ELSE C2 = 1 FinalSet = A2 + B2 + C2 ' No lie IF FinalSet = 0 THEN LiedOn = 0: GOTO 10 ' Lie, determine which question and correct the lie if needed IF FinalSet = Set1 THEN LiedOn = 1: GOTO 10 IF FinalSet = Set2 THEN LiedOn = 2: GOTO 10 IF FinalSet = Set3 THEN LiedOn = 3: GOTO 10 IF FinalSet = Set4 AND ANSWER4$ = "Y" THEN ANSWER4$ = "N": LiedOn = 4: GOTO 10 IF FinalSet = Set4 AND ANSWER4$ = "N" THEN ANSWER4$ = "Y": LiedOn = 4: GOTO 10 IF FinalSet = Set5 AND ANSWER5$ = "Y" THEN ANSWER5$ = "N": LiedOn = 5: GOTO 10 IF FinalSet = Set5 AND ANSWER5$ = "N" THEN ANSWER5$ = "Y": LiedOn = 5: GOTO 10 IF FinalSet = Set6 AND ANSWER6$ = "Y" THEN ANSWER6$ = "N": LiedOn = 6: GOTO 10 IF FinalSet = Set6 AND ANSWER6$ = "N" THEN ANSWER6$ = "Y": LiedOn = 6: GOTO 10 IF FinalSet = Set7 AND ANSWER7$ = "Y" THEN ANSWER7$ = "N": LiedOn = 7: GOTO 10 IF FinalSet = Set7 AND ANSWER7$ = "N" THEN ANSWER7$ = "Y": LiedOn = 7: GOTO 10 ' Simple binary addition determines the number 10 X = 0 IF ANSWER4$ = "Y" THEN X = X + 8 IF ANSWER5$ = "Y" THEN X = X + 4 IF ANSWER6$ = "Y" THEN X = X + 2 IF ANSWER7$ = "Y" THEN X = X + 1 PRINT "" PRINT "" IF LiedOn = 0 THEN PRINT "Your number was"; X; "." IF LiedOn <> 0 THEN PRINT "Your number was"; X; "and you lied on question number"; LiedOn; "." PRINT "" INPUT "Am I right? (Y/N)", R$ R$ = UCASE$(R$) IF R$ = "Y" THEN PRINT "": PRINT "I told you so - I'm always right!": END IF R$ = "N" THEN PRINT "": PRINT "Oh well. Try it again!": END