Solve a Hidato puzzle: Difference between revisions
Content added Content deleted
(Added Uiua solution) |
|||
Line 5,190: | Line 5,190: | ||
More complex cases are solvable with an [[/Extended Tcl solution|extended version of this code]], though that has more onerous version requirements. |
More complex cases are solvable with an [[/Extended Tcl solution|extended version of this code]], though that has more onerous version requirements. |
||
=={{header|Uiua}}== |
|||
{{Works with |Uiua|0.12.0-dev.1}} |
|||
Simple adaptation of the [https://rosettacode.org/wiki/Solve_a_Numbrix_puzzle#Uiua Numbrix solution]. |
|||
Uses experimental '''astar''' and '''λ (swizzle)''' operators. |
|||
<syntaxhighlight lang="uiua"> |
|||
# Experimental! |
|||
G ← [[0 33 35 0 0 ¯1 ¯1 ¯1] |
|||
[0 0 24 22 0 ¯1 ¯1 ¯1] |
|||
[0 0 0 21 0 0 ¯1 ¯1] |
|||
[0 26 0 13 40 11 ¯1 ¯1] |
|||
[27 0 0 0 9 0 1 ¯1] |
|||
[¯1 ¯1 0 0 18 0 0 ¯1] |
|||
[¯1 ¯1 ¯1 ¯1 0 7 0 0] |
|||
[¯1 ¯1 ¯1 ¯1 ¯1 ¯1 5 0]] |
|||
S ← /×△G # Total size. |
|||
N ← /+≠¯1♭G |
|||
Width ← ⧻⊢G |
|||
Dirs ← [¯.1 ⊓∩(+1)∩(-1),,,,¯.Width] # D8 directions. |
|||
DiaD ← /↥⌵-∩(⊟⊃(◿|⌊÷)Width) # Diagonal 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))▽⊙(⍉⊟)↥0±,⊗.. # [pos num] sorted by nums. |
|||
# Ensure each pair of placed numbers have DiaD <= number differemce. |
|||
Heur ← ⨬(-1N|999)=0/↧≡(≥⊙(⌵/-)DiaD°⊟°⊟⍉)◫2Placed |
|||
astar(Nodes|Heur|¬∊0)♭G |
|||
↯△G⊡¯1°□⊢⊙◌ |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
╭─ |
|||
╷ 32 33 35 36 37 ¯1 ¯1 ¯1 |
|||
31 34 24 22 38 ¯1 ¯1 ¯1 |
|||
30 25 23 21 12 39 ¯1 ¯1 |
|||
29 26 20 13 40 11 ¯1 ¯1 |
|||
27 28 14 19 9 10 1 ¯1 |
|||
¯1 ¯1 15 16 18 8 2 ¯1 |
|||
¯1 ¯1 ¯1 ¯1 17 7 6 3 |
|||
¯1 ¯1 ¯1 ¯1 ¯1 ¯1 5 4 |
|||
╯ |
|||
</pre> |
|||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{trans|Kotlin}} |
{{trans|Kotlin}} |