Twelve statements: Difference between revisions
Content deleted Content added
m →{{header|Uiua}}: final fix :-) |
→{{header|Uiua}}: Improved algorithm |
||
Line 4,116: | Line 4,116: | ||
=={{header|Uiua}}== |
=={{header|Uiua}}== |
||
{{works with|Uiua|0. |
{{works with|Uiua|0.12.0-dev.1}} |
||
Defined the rules as functions to avoid the main loop devolving into line noise :-) |
Defined the rules as functions to avoid the main loop devolving into line noise :-) |
||
<syntaxhighlight lang=" |
<syntaxhighlight lang="uiua"> |
||
Even ← =1◿2⇡⧻ # nb indexes are zero-based |
Even ← =1◿2⇡⧻ # nb indexes are zero-based |
||
S₁ ← =12⧻ # Total is always twelve (don't test) |
|||
S₂ ← =3⧻⊚↘6 # Three of last six are true |
|||
S₃ ← =2⧻⊚⊏⊚Even. # Exactly two even rules are true |
|||
S₄ ← ⨬(⋅1|/↧)⊢.⊏4_5_6 # If 5 is true so must 6 and 7 be. |
|||
S₅ ← /↧¬⊏[1 2 3] # 2, 3, 4 are all false |
|||
S₆ ← =4⧻⊚⊏⊚¬Even. # Four odd rules are true |
|||
S₇ ← =1/+⊏1_2 # 2 xor 3 |
|||
S₈ ← ⨬(⋅1|/↧)⊢.⇌⊏4_5_6 # If 7 is true so are 6 and 5 |
|||
S₉ ← =3⧻⊚↙6 # Three of first six are true |
|||
S₁₀ ← /↧⊏10_11 # 11 and 12 are both true |
|||
S₁₁ ← =1/+⊏6_7_8 # Exactly one of 7, 8, 9 is true |
|||
S₁₂ ← =4/+↘¯1 # Exactly four of above are true |
|||
⋯+1×2⇡2048 # |
⋯+1×2⇡2048 # Generate bits to represent all states of rules 2-12 |
||
≡( |
≡( |
||
# Test each rule against the data and concatenate |
# Test each rule against the data and concatenate |
||
⟜[⊃(S₁|S₂|S₃|S₄|S₅|S₆|S₇|S₈|S₉|S₁₀|S₁₁|S₁₂)] |
|||
:[⊃⊃⊃⊃⊃⊃⊃⊃⊃⊃⊃SA SB SC SD SE SF SG SH SI SJ SK SL]. |
|||
⊟∩□:⊙(⊚⌵-). # Append hit-count |
⊟∩□:⊙(⊚⌵-). # Append hit-count |
||
) |
) |
||
# Partition by fit, keep only hits and near-misses |
°⊟↙2⊕□≡(◇⧻⊢). # Partition by fit, keep only hits and near-misses |
||
&p$"Succeeds when the following rules are true:\n_\n"+1◇⊚⊢↘1◇⊢ |
|||
°⊟↙2⊕□≡(◇⧻⊢). |
|||
# Print results |
|||
&p"\nNear Misses"&s+1◇⊚⊢↘1◇⊢&p"Hits" |
|||
⊏⍏≡⊢.°□ # Sort misses |
⊏⍏≡⊢.°□ # Sort misses |
||
&p"Near Misses:" |
|||
≡(⊃(&p+1⊚°□⊢↘1)(&pf"\t"&pf+1◇⊢⊢&pf"Fails at ")) |
|||
≡(&p$"Fails at _\t _"⊃(+1◇⊢⊢|+1⊚°□⊢↘1)) |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Succeeds when the following rules are true: |
|||
Hits |
|||
[1 3 4 6 7 11] |
[1 3 4 6 7 11] |
||
Near Misses |
Near Misses: |
||
Fails at 6 [1 4 6 8 9] |
Fails at 6 [1 4 6 8 9] |
||
Fails at 7 [1 3 4 8 9] |
Fails at 7 [1 3 4 8 9] |
||
Fails at 8 [1 4] |
Fails at 8 [1 4] |
||
Fails at 8 [1 5] |
Fails at 8 [1 5] |
||
Fails at 8 [1 2 4 7 8 9] |
Fails at 8 [1 2 4 7 8 9] |
||
Fails at 8 [1 5 6 9 11] |
Fails at 8 [1 5 6 9 11] |
||
Fails at 9 [1 3 4 6 7 9] |
Fails at 9 [1 3 4 6 7 9] |
||
Fails at 10 [1 2 4 7 9 10] |
Fails at 10 [1 2 4 7 9 10] |
||
Fails at 11 [1 5 8] |
Fails at 11 [1 5 8] |
||
Fails at 12 [1 5 8 11] |
Fails at 12 [1 5 8 11] |
||
Fails at 12 [1 2 4 7 9 12] |
Fails at 12 [1 2 4 7 9 12] |
||
Fails at 12 [1 4 8 10 11 12] |
Fails at 12 [1 4 8 10 11 12] |
||
Fails at 12 [1 5 8 10 11 12] |
Fails at 12 [1 5 8 10 11 12] |
||
</pre> |
|||
=={{header|VBA}}== |
=={{header|VBA}}== |