How to resolve the algorithm Twelve statements step by step in the BBC BASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Twelve statements step by step in the BBC BASIC programming language
Table of Contents
Problem Statement
This puzzle is borrowed from math-frolic.blogspot.
Given the following twelve statements, which of them are true?
When you get tired of trying to figure it out in your head, write a program to solve it, and print the correct answer or answers.
Print out a table of near misses, that is, solutions that are contradicted by only a single statement.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Twelve statements step by step in the BBC BASIC programming language
Source code in the bbc programming language
nStatements% = 12
DIM Pass%(nStatements%), T%(nStatements%)
FOR try% = 0 TO 2^nStatements%-1
REM Postulate answer:
FOR stmt% = 1 TO 12
T%(stmt%) = (try% AND 2^(stmt%-1)) <> 0
NEXT
REM Test consistency:
Pass%(1) = T%(1) = (nStatements% = 12)
Pass%(2) = T%(2) = ((T%(7)+T%(8)+T%(9)+T%(10)+T%(11)+T%(12)) = -3)
Pass%(3) = T%(3) = ((T%(2)+T%(4)+T%(6)+T%(8)+T%(10)+T%(12)) = -2)
Pass%(4) = T%(4) = ((NOT T%(5) OR (T%(6) AND T%(7))))
Pass%(5) = T%(5) = (NOT T%(2) AND NOT T%(3) AND NOT T%(4))
Pass%(6) = T%(6) = ((T%(1)+T%(3)+T%(5)+T%(7)+T%(9)+T%(11)) = -4)
Pass%(7) = T%(7) = ((T%(2) EOR T%(3)))
Pass%(8) = T%(8) = ((NOT T%(7) OR (T%(5) AND T%(6))))
Pass%(9) = T%(9) = ((T%(1)+T%(2)+T%(3)+T%(4)+T%(5)+T%(6)) = -3)
Pass%(10) = T%(10) = (T%(11) AND T%(12))
Pass%(11) = T%(11) = ((T%(7)+T%(8)+T%(9)) = -1)
Pass%(12) = T%(12) = ((T%(1)+T%(2)+T%(3)+T%(4)+T%(5)+T%(6) + \
\ T%(7)+T%(8)+T%(9)+T%(10)+T%(11)) = -4)
CASE SUM(Pass%()) OF
WHEN -11:
PRINT "Near miss with statements ";
FOR stmt% = 1 TO 12
IF T%(stmt%) PRINT ; stmt% " ";
IF NOT Pass%(stmt%) miss% = stmt%
NEXT
PRINT "true (failed " ;miss% ")."
WHEN -12:
PRINT "Solution! with statements ";
FOR stmt% = 1 TO 12
IF T%(stmt%) PRINT ; stmt% " ";
NEXT
PRINT "true."
ENDCASE
NEXT try%
END
You may also check:How to resolve the algorithm Dragon curve step by step in the Racket programming language
You may also check:How to resolve the algorithm Calendar step by step in the J programming language
You may also check:How to resolve the algorithm Character codes step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Copy a string step by step in the Prolog programming language
You may also check:How to resolve the algorithm Fast Fourier transform step by step in the Nim programming language