Twelve statements: Difference between revisions

Added 11l
(Added 11l)
Line 34:
Print out a table of near misses, that is, solutions that are contradicted by only a single statement.
<br><br>
 
=={{header|11l}}==
{{trans|Nim}}
{{trans|Python}}
 
<lang 11l>[([Int] -> Bool)] predicates
predicates [+]= st -> st.len == 12
predicates [+]= st -> sum(st[(len)-6 ..]) == 3
predicates [+]= st -> sum(st[(1..).step(2)]) == 2
predicates [+]= st -> I st[4] {(st[5] [&] st[6])} E 1
predicates [+]= st -> sum(st[1.<4]) == 0
predicates [+]= st -> sum(st[(0..).step(2)]) == 4
predicates [+]= st -> sum(st[1.<3]) == 1
predicates [+]= st -> I st[6] {(st[4] [&] st[5])} E 1
predicates [+]= st -> sum(st[0.<6]) == 3
predicates [+]= st -> (st[10] [&] st[11])
predicates [+]= st -> sum(st[6.<9]) == 1
predicates [+]= st -> sum(st[0.<11]) == 4
 
F to_str(b)
R (0.<12).filter(i -> @b[i]).map(i -> i + 1).join(‘ ’)
 
print(‘Exact hits:’)
L(n) 4096
V bools = [0] * 12
L(i) 12
I n [&] (1 << (11 - i)) != 0
bools[i] = 1
 
L(predicate) predicates
I Int(predicate(bools)) != bools[L.index]
L.break
L.was_no_break
print(‘ ’to_str(bools))
 
print("\nNear misses:")
L(n) 4096
V bools = [0] * 12
L(i) 12
I n [&] (1 << (11 - i)) != 0
bools[i] = 1
 
V count = 0
L(predicate) predicates
I Int(predicate(bools)) == bools[L.index]
count++
I count == 11
L(predicate) predicates
V i = L.index
I Int(predicate(bools)) != bools[i]
print(f:‘ (Fails at statement {i + 1:2}) {to_str(bools)}’)
L.break</lang>
 
{{out}}
<pre>
Exact hits:
1 3 4 6 7 11
 
Near misses:
(Fails at statement 1) 5 8 11
(Fails at statement 1) 5 8 10 11 12
(Fails at statement 1) 4 8 10 11 12
(Fails at statement 8) 1 5
(Fails at statement 11) 1 5 8
(Fails at statement 12) 1 5 8 11
(Fails at statement 12) 1 5 8 10 11 12
(Fails at statement 8) 1 5 6 9 11
(Fails at statement 8) 1 4
(Fails at statement 12) 1 4 8 10 11 12
(Fails at statement 6) 1 4 6 8 9
(Fails at statement 7) 1 3 4 8 9
(Fails at statement 9) 1 3 4 6 7 9
(Fails at statement 12) 1 2 4 7 9 12
(Fails at statement 10) 1 2 4 7 9 10
(Fails at statement 8) 1 2 4 7 8 9
</pre>
 
=={{header|Ada}}==
1,480

edits