Solve the no connection puzzle: Difference between revisions
Content deleted Content added
m →annotated solutions: used a more idiomatic way of creating a number of blanks that doesn't require counting. |
Added Elixir |
||
Line 484: | Line 484: | ||
5 6 |
5 6 |
||
Tested 12094 positions and did 20782 swaps.</pre> |
Tested 12094 positions and did 20782 swaps.</pre> |
||
=={{header|Elixir}}== |
|||
{{trans|Ruby}} |
|||
This solution uses HLPsolver from [[Solve_a_Hidato_puzzle#Elixir | here]] |
|||
<lang elixir># It solved if connected A and B, connected G and H (according to the video). |
|||
# require HLPsolver |
|||
adjacent = for i <- -2..2, j <- -2..2, not(i in -1..1 and j in -1..1), do: {i,j} |
|||
layout = ~S""" |
|||
A - B |
|||
/|\ /|\ |
|||
/ | X | \ |
|||
/ |/ \| \ |
|||
C - D - E - F |
|||
\ |\ /| / |
|||
\ | X | / |
|||
\|/ \|/ |
|||
G - H |
|||
""" |
|||
board = """ |
|||
. 0 0 . |
|||
0 1 0 0 |
|||
. 0 0 . |
|||
""" |
|||
HLPsolver.solve(board, adjacent, false) |
|||
|> Enum.sort |> Enum.map(fn {_,cell} -> cell.value end) |
|||
|> Enum.zip(~w[A B C D E F G H]) |
|||
|> Enum.reduce(layout, fn {n,c},acc -> String.replace(acc, c, to_string(n)) end) |
|||
|> IO.puts</lang> |
|||
{{out}} |
|||
<pre> |
|||
4 - 6 |
|||
/|\ /|\ |
|||
/ | X | \ |
|||
/ |/ \| \ |
|||
7 - 1 - 8 - 2 |
|||
\ |\ /| / |
|||
\ | X | / |
|||
\|/ \|/ |
|||
3 - 5 |
|||
</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |