Solve a Numbrix puzzle: Difference between revisions
Content deleted Content added
Added Uiua solution |
|||
Line 3,998:
</pre>
=={{header|Uiua}}==
{{Works with |Uiua|0.12.0-dev.1}}
Uses experimental '''astar''' and '''λ (swizzle)''' operators.
<syntaxhighlight lang="uiua">
# Experimental!
G ← [[0 0 0 0 0 0 0 0 0]
[0 11 12 15 18 21 62 61 0]
[0 6 0 0 0 0 0 60 0]
[0 33 0 0 0 0 0 57 0]
[0 32 0 0 0 0 0 56 0]
[0 37 0 1 0 0 0 73 0]
[0 38 0 0 0 0 0 72 0]
[0 43 44 47 48 51 76 77 0]
[0 0 0 0 0 0 0 0 0]]
S ← /×△G # Total size.
Width ← ⧻⊢G
Dirs ← [∩(¯.)1Width] # D4 directions.
ManD ← /+⌵-∩(⊟⊃(◿|⌊÷)Width) # Manhattan dist.
Ns ← ▽:⟜≡(=0⊡)⊙¤▽⊸≡(↧⊃(≥0|<S))+Dirs ¤ # Valid empty Ns.
Next ← +1⊢⊚=S⊗+1⇡S # Next unplaced number.
Nodes ← ⍣(≡(⍜⊡⋅∘)λbCA⊙Ns:⊗-1,,Next..|[]) # Valid next boards from here.
Placed ← ⊏(⍏⊸≡(⊡1))▽⊙(⍉⊟)±,⊗.. # [pos num] sorted by nums.
# Ensure each pair of placed numbers have ManD <= number differemce.
Heur ← ⨬(-1S|999)=0/↧≡(≥⊙(⌵/-)ManD°⊟°⊟⍉)◫2Placed
astar(Nodes|Heur|¬∊0)♭G
↯△G⊡¯1°□⊢⊙◌
</syntaxhighlight>
{{out}}
<pre>
╭─
╷ 9 10 13 14 19 20 63 64 65
8 11 12 15 18 21 62 61 66
7 6 5 16 17 22 59 60 67
34 33 4 3 24 23 58 57 68
35 32 31 2 25 54 55 56 69
36 37 30 1 26 53 74 73 70
39 38 29 28 27 52 75 72 71
40 43 44 47 48 51 76 77 78
41 42 45 46 49 50 81 80 79
╯
</pre>
=={{header|Wren}}==
{{libheader|Wren-sort}}
|