This puzzle is borrowed from   math-frolic.blogspot.



Given the following twelve statements, which of them are true?

 1.  This is a numbered list of twelve statements.
 2.  Exactly 3 of the last 6 statements are true.
 3.  Exactly 2 of the even-numbered statements are true.
 4.  If statement 5 is true, then statements 6 and 7 are both true.
 5.  The 3 preceding statements are all false.
 6.  Exactly 4 of the odd-numbered statements are true.
 7.  Either statement 2 or 3 is true, but not both.
 8.  If statement 7 is true, then 5 and 6 are both true.
 9.  Exactly 3 of the first 6 statements are true.
10.  The next two statements are both true.
11.  Exactly 1 of statements 7, 8 and 9 are true.
12.  Exactly 4 of the preceding statements are true.



Task

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.



Extra credit

Print out a table of near misses, that is, solutions that are contradicted by only a single statement.




def indexed(filter):
  . as $in
  | reduce range(0;length) as $i ([]; if ($i | filter) then . + [$in[$i]] else . end);
 
def count(value): map(select(. == value)) | length;
 
# The truth or falsity of the 12 statements can be captured in an array of size 12:
def generate(k):
  if k == 1 then [true], [false]
  else generate(1) + generate(k-1)
  end;
 
# Input: a boolean array
def evaluate:
  [ (length == 12),                                          #1
    ((.[6:] | count(true)) == 3),                            #2
    ((indexed(. % 2 == 1) | count(true)) == 2),              #3
    (if .[4] then .[5] and .[6] else true end),              #4
    ((.[1:4] | count(false)) == 3),                          #5
    ((indexed(. % 2 == 0) | count(true)) == 4),              #6
    (([.[1], .[2]] | count(true)) == 1),                     #7
    (if .[6] then .[4] and .[5] else true end),              #8
    ((.[0:6] | count(true)) == 3),                           #9
    (.[10] and .[11]),                                      #10
    ((.[6:9] | count(true)) == 1),                          #11
    ((.[0:11] | count(true)) == 4)                          #12
  ];
 
# The following query generates the solution to the problem:
# generate(12) | . as $vector | if evaluate == $vector then $vector else empty end
 
# Running "task" as defined next would generate 
# both the general solution as well as the off-by-one solutions:
 
def task:
 
  # count agreements
  def agreed(x;y): reduce range(0;x|length) as $i (0; if x[$i] == y[$i] then .+1 else . end);
 
  reduce generate(12) as $vector
    ([]; ($vector | evaluate) as $e
         | agreed($vector; $e) as $agreed
         | if $agreed == 12 then [[12,$vector]] + .
           elif $agreed == 11 then . +  [[11, $vector]]
           else .
           end);
 
# Since the solutions have been given elsewhere, we simply count the
# number of exact and off-by-one solutions:
 
task | length