Solve a Numbrix puzzle: Difference between revisions

Content deleted Content added
Midaz (talk | contribs)
Added Uiua solution
Midaz (talk | contribs)
→‎{{header|Uiua}}: Improved algorithm
 
Line 4,000: Line 4,000:
=={{header|Uiua}}==
=={{header|Uiua}}==
{{Works with |Uiua|0.12.0-dev.1}}
{{Works with |Uiua|0.12.0-dev.1}}
Uses experimental '''astar''' and '''λ (swizzle)''' operators.
Uses experimental '''astar''' operator. Rewritten to avoid using now deprecated '''λ (swizzle)''' operator :-(
<syntaxhighlight lang="uiua">
<syntaxhighlight lang="uiua">
# Experimental!
# Experimental!
Line 4,014: Line 4,014:
S ← /×△G # Total size.
S ← /×△G # Total size.
Width ← ⧻⊢G
Width ← ⧻⊢G
Dirs ← [∩(¯.)1Width] # D4 directions.
Dirs ← [∩(¯.)1Width] # D4 directions.
ManD ← /+⌵-∩(⊟⊃(◿|⌊÷)Width) # Manhattan dist.
ManD ← /+⌵-∩(⊟⊃(◿|⌊÷)Width) # Manhattan dist.
Ns ← ▽:⟜≡(=0⊡)⊙¤▽⊸≡(↧⊃(≥0|<S))+Dirs ¤ # Valid empty Ns.
Ns ← ▽:⟜≡(=0⊡)⊙¤▽⊸≡(↧⊃(≥0|<S))+Dirs ¤ # Valid empty Ns.
Next ← +1⊢⊚=S⊗+1⇡S # Next unplaced number.
Next ← +1⊢⊚=S⊗+1⇡S # Next unplaced number.
Nodes ← ⍣(≡(⍜⊡⋅∘)λbCA⊙Ns:⊗-1,,Next..|[]) # Valid next boards from here.
Nodes ← ⍣(≡(⍜⊡⋅∘)⊃(⋅∘|¤⋅⋅∘|¤∘)⊙Ns:⊗-1,,Next..|[]) # Valid next boards from here.
Placed ← ⊏(⍏⊸≡(⊡1))▽⊙(⍉⊟)±,⊗.. # [pos num] sorted by nums.
Placed ← ⊏(⍏⊸≡(⊡1))▽⊙(⍉⊟)±,⊗.. # [pos num] sorted by nums.
# Ensure each pair of placed numbers have ManD <= number differemce.
# Ensure each pair of placed numbers have ManD <= number differemce.
Heur ← ⨬(-1S|999)=0/↧≡(≥⊙(⌵/-)ManD°⊟°⊟⍉)◫2Placed
Heur ← ⨬(-1S|999)=0/↧≡(≥⊙(⌵/-)ManD°⊟°⊟⍉)◫2Placed
Line 4,039: Line 4,039:
</pre>
</pre>

=={{header|Wren}}==
=={{header|Wren}}==
{{libheader|Wren-sort}}
{{libheader|Wren-sort}}