Twelve statements: Difference between revisions

Content deleted Content added
m →‎{{header|Python}}: Consistency with output
Line 470: Line 470:
Note: we choose to adapt the statement numbering to zero-based indexing in the constraintinfo lambda expressions but convert back to one-based on output.
Note: we choose to adapt the statement numbering to zero-based indexing in the constraintinfo lambda expressions but convert back to one-based on output.


The program uses brute force to generate all possible boolean values of the twelve statements then checks if the actual value of the statements matches the proposed or matches apart from exactly one deviation. Pythons' boolean values True, False are converted to the integer values one, zero in numerical contexts. This fact is used in the lambda expressions that use function sum.
The program uses brute force to generate all possible boolean values of the twelve statements then checks if the actual value of the statements matches the proposed or matches apart from exactly one deviation. Python's boolean type <tt>bool</tt>is a subclass of <tt>int</tt>, so boolean values True, False can be used as integers (1, 0, respectively) in numerical contexts. This fact is used in the lambda expressions that use function sum.
<lang python>
<lang python>
from itertools import product
from itertools import product