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.




class LogicPuzzle {
  val s = new Array[Boolean](13)
  var count = 0
 
  def check2: Boolean = {
    var count = 0
    for (k <- 7 to 12) if (s(k)) count += 1
 
    s(2) == (count == 3)
  }
 
  def check3: Boolean = {
    var count = 0
    for (k <- 2 to 12 by 2) if (s(k)) count += 1
 
    s(3) == (count == 2)
  }
 
  def check4: Boolean = s(4) == (!s(5) || s(6) && s(7))
 
  def check5: Boolean = s(5) == (!s(2) && !s(3) && !s(4))
 
  def check6: Boolean = {
    var count = 0
    for (k <- 1 to 11 by 2) if (s(k)) count += 1
    s(6) == (count == 4)
  }
 
  def check7: Boolean = s(7) == ((s(2) || s(3)) && !(s(2) && s(3)))
 
  def check8: Boolean = s(8) == (!s(7) || s(5) && s(6))
 
  def check9: Boolean = {
    var count = 0
    for (k <- 1 to 6) if (s(k)) count += 1
 
    s(9) == (count == 3)
  }
 
  def check10: Boolean = s(10) == (s(11) && s(12))
 
  def check11: Boolean = {
    var count = 0
    for (k <- 7 to 9) if (s(k)) count += 1
 
    s(11) == (count == 1)
  }
 
  def check12: Boolean = {
    var count = 0
    for (k <- 1 to 11) if (s(k)) count += 1
    s(12) == (count == 4)
  }
 
  def check(): Unit = {
    if (check2 && check3 && check4 && check5 && check6 && check7 && check8 && check9 && check10 && check11 && check12) {
      for (k <- 1 to 12) if (s(k)) print(k + " ")
      println()
      count += 1
    }
  }
 
  def recurseAll(k: Int): Unit = {
    if (k == 13) check()
    else {
      s(k) = false
      recurseAll(k + 1)
      s(k) = true
      recurseAll(k + 1)
    }
  }
}
 
object LogicPuzzle extends App {
  val p = new LogicPuzzle
  p.s(1) = true
  p.recurseAll(2)
  println()
  println(s"${p.count} Solutions found.")
 
}