Twelve statements: Difference between revisions

m
→‎{{header|Uiua}}: final fix :-)
imported>Arakov
m (→‎{{header|Uiua}}: final fix :-))
 
(8 intermediate revisions by 4 users not shown)
Line 1,406:
Missed by statement: 12
T F F F T F F T F T T T</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight lang=easylang>
len t[] 12
func f n .
if n = 1
return if 12 = 12
elif n = 2
for i = 7 to 12
s += t[i]
.
return if s = 3
elif n = 3
for i = 2 step 2 to 12
s += t[i]
.
return if s = 2
elif n = 4
if t[5] = 1
return if t[6] + t[7] = 2
.
return 1
elif n = 5
for i = 2 to 4
s += t[i]
.
return if s = 0
elif n = 6
for i = 1 step 2 to 11
s += t[i]
.
return if s = 4
elif n = 7
return if t[2] + t[3] = 1
elif n = 8
if t[7] = 1
return if t[5] + t[6] = 2
.
return 1
elif n = 9
for i = 1 to 6
s += t[i]
.
return if s = 3
elif n = 10
return if t[11] + t[12] = 2
elif n = 11
for i = 7 to 9
s += t[i]
.
return if s = 1
elif n = 12
for i = 1 to 11
s += t[i]
.
return if s = 4
.
.
for tst = 0 to 4095
h = tst
for i to 12
t[i] = h mod 2
h = h div 2
.
s = 0
for i to 12
s += if f i = t[i]
.
if s = 12
print t[]
.
.
</syntaxhighlight>
{{out}}
<pre>
[ 1 0 1 1 0 1 1 0 0 0 1 0 ]
</pre>
 
 
=={{header|Eiffel}}==
Line 1,605 ⟶ 1,683:
printSolution(bits)
= self.zipBy(bits,
(s,b => s.iif("T","F") + (s.xor:(b)).iif("* "," "))).summarize(new StringWriter());
 
toBit()
Line 1,615 ⟶ 1,693:
(bits => bits.Length == 12),
(bits => bits.last(6).selectBy::(x => x.toBit()).summarize() == 3 ),
(bits => bits.zipBy(new Range(1, 12),
(x,i => (i.toInt().isEven()).and:(x).toBit())).summarize() == 2 ),
(bits => bits[4].iif(bits[5] && bits[6],true) ),
Line 1,625 ⟶ 1,703:
(bits => bits.zipBy(new Range(1, 12),
(x,i => (i.toInt().isOdd()).and:(x).toBit() )).summarize() == 4 ),
(bits => bits[1].xor(bits[2]) ),
Line 1,631 ⟶ 1,709:
(bits => bits[6].iif(bits[5] && bits[4],true) ),
(bits => bits.top(6).selectBy::(x => x.toBit() ).summarize() == 3 ),
(bits => bits[10] && bits[11] ),
Line 1,637 ⟶ 1,715:
(bits => (bits[6].toBit() + bits[7].toBit() + bits[8].toBit())==1 ),
(bits => bits.top(11).selectBy::(x => x.toBit()).summarize() == 4 )
};
 
Line 1,644 ⟶ 1,722:
console.writeLine();
for(int n := 0,; n < 2.power(12),; n += 1)
{
var bits := BitArray32.load(n).top(12).toArray();
var results := puzzle.selectBy::(r => r(bits)).toArray();
var counts := bits.zipBy(results, (b,r => b.xor:(r).toBit() )).summarize();
 
counts =>
0 { console.printLine("Total hit :",results.printSolution:(bits)) }
1 { console.printLine("Near miss :",results.printSolution:(bits)) }
12 { console.printLine("Total miss:",results.printSolution:(bits)) };
};
Line 3,950 ⟶ 4,028:
close 1 2 4 7 9 10 (wrong 10)
close 1 2 4 7 8 9 (wrong 8)</pre>
 
 
=={{header|uBasic/4tH}}==
Line 4,035 ⟶ 4,114:
Near miss with statements 5 8 10 11 12 true (failed 1).
Near miss with statements 1 5 8 10 11 12 true (failed 12).</pre>
 
=={{header|Uiua}}==
{{works with|Uiua|0.10.0-dev.1}}
 
Defined the rules as functions to avoid the main loop devolving into line noise :-)
 
<syntaxhighlight lang="Uiua">
Even ← =1◿2⇡⧻ # nb indexes are zero-based
SA ← =12⧻ # Total is always twelve (don't test)
SB ← =3⧻⊚↘6 # Three of last six are true
SC ← =2⧻⊚⊏⊚Even. # Exactly two even rules are true
SD ← ⟨1◌|/×⟩⊢.↙3↘4 # If 5 is true so are 6 and 7
SE ← /׬⊏[1 2 3] # 2, 3, 4 are all false
SF ← =4⧻⊚⊏⊚¬Even. # Four odd rules are true
SG ← =1/+↙2↘1 # 2 xor 3
SH ← ⟨1◌|/×⟩⊢.⇌↙3↘4 # If 7 is true so are 6 and 5
SI ← =3⧻⊚↙6 # Three of first six are true
SJ ← /×⊏[10 11] # 11 and 12 are both true
SK ← =1/+⊏[6 7 8] # Exactly one of 7, 8, 9 is true
SL ← =4/+↘¯1 # Exactly four of above are true
 
⋯+1×2⇡2048 # Brute force sensible combinations
≡(
# Test each rule against the data and concatenate
:[⊃⊃⊃⊃⊃⊃⊃⊃⊃⊃⊃SA SB SC SD SE SF SG SH SI SJ SK SL].
⊟∩□:⊙(⊚⌵-). # Append hit-count
)
 
# Partition by fit, keep only hits and near-misses
°⊟↙2⊕□≡(◇⧻⊢).
 
# Print results
&p"\nNear Misses"&s+1◇⊚⊢↘1◇⊢&p"Hits"
⊏⍏≡⊢.°□ # Sort misses
≡(⊃(&p+1⊚°□⊢↘1)(&pf"\t"&pf+1◇⊢⊢&pf"Fails at "))
</syntaxhighlight>
{{out}}
<pre>
Hits
[1 3 4 6 7 11]
 
Near Misses
Fails at 6 [1 4 6 8 9]
Fails at 7 [1 3 4 8 9]
Fails at 8 [1 4]
Fails at 8 [1 5]
Fails at 8 [1 2 4 7 8 9]
Fails at 8 [1 5 6 9 11]
Fails at 9 [1 3 4 6 7 9]
Fails at 10 [1 2 4 7 9 10]
Fails at 11 [1 5 8]
Fails at 12 [1 5 8 11]
Fails at 12 [1 2 4 7 9 12]
Fails at 12 [1 4 8 10 11 12]
Fails at 12 [1 5 8 10 11 12]</pre>
 
=={{header|VBA}}==
Line 4,129 ⟶ 4,263:
{{trans|Kotlin}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Conv, Fmt
 
var predicates = [
67

edits