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.




constraints = [
  ->(st) { st.size == 12 }, 
  ->(st) { st.last(6).count(true) == 3 },
  ->(st) { st.each_slice(2).map(&:last).count(true) == 2 },
  ->(st) { st[4] ? (st[5] & st[6]) : true },
  ->(st) { st[1..3].none? },
  ->(st) { st.each_slice(2).map(&:first).count(true) == 4 },
  ->(st) { st[1] ^ st[2] },
  ->(st) { st[6] ? (st[4] & st[5]) : true  }, 
  ->(st) { st.first(6).count(true) == 3 },
  ->(st) { st[10] & st[11] },
  ->(st) { st[6..8].one? },
  ->(st) { st[0,11].count(true) == 4 },
]
 
Result = Struct.new(:truths, :consistency)
 
results = [true, false].repeated_permutation(12).map do |truths|
  Result.new(truths, constraints.zip(truths).map {|cn,truth| cn[truths] == truth })
end
 
puts "solution:", 
  results.find {|r| r.consistency.all? }.truths.to_s
 
puts "\nnear misses: "
near_misses = results.select {|r| r.consistency.count(false) == 1 }
near_misses.each do |r|
  puts "missed by statement #{r.consistency.index(false) + 1}", r.truths.to_s
end