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.




// version 1.1.3
 
typealias Predicate = (String) -> Boolean
 
val predicates = listOf<Predicate>( 
    { it.length == 13 },  // indexing starts at 0 but first bit ignored
    { (7..12).count { i -> it[i] == '1' } == 3 },
    { (2..12 step 2).count { i -> it[i] == '1' } == 2 },
    { it[5] == '0' || (it[6] == '1' && it[7] == '1') }, 
    { it[2] == '0' && it[3]  == '0' && it[4] == '0' },
    { (1..11 step 2).count { i -> it[i] == '1' } == 4 },
    { (it[2] == '1') xor (it[3] == '1') },
    { it[7] == '0' || (it[5] == '1' && it[6] == '1') },
    { (1..6).count { i -> it[i] == '1' } == 3 },
    { it[11] == '1' && it[12] == '1' },
    { (7..9).count { i -> it[i] == '1' } == 1 },
    { (1..11).count { i -> it[i] == '1' } == 4 }
)
 
fun show(s: String, indent: Boolean) {
    if (indent) print("    ")
    for (i in s.indices) if (s[i] == '1') print("$i ")
    println()
} 
 
fun main(args: Array<String>) {
    println("Exact hits:")
    for (i in 0..4095) {
        val s = i.toString(2).padStart(13, '0')
        var j = 1
        if (predicates.all { it(s) == (s[j++] == '1') }) show(s, true)
    }
 
    println("\nNear misses:")
    for (i in 0..4095) {
        val s = i.toString(2).padStart(13, '0')
        var j = 1
        if (predicates.count { it(s) == (s[j++] == '1') } == 11) {
            var k = 1
            val iof = predicates.indexOfFirst { it(s) != (s[k++] == '1') } + 1
            print("    (Fails at statement ${"%2d".format(iof)})  ")
            show(s, false)
        }
    }    
}