Solve the no connection puzzle: Difference between revisions
Content added Content deleted
m (A category goes in the task template, not the title) |
(Added Mathematica) |
||
Line 684: | Line 684: | ||
\|/ \|/ |
\|/ \|/ |
||
3 4</lang> |
3 4</lang> |
||
=={{header|Mathematica}}== |
|||
This one simply takes all permutations of the pegs and filters out invalid solutions. |
|||
<lang Mathematica>sol = Fold[ |
|||
Select[#, |
|||
Function[perm, Abs[perm[[#2[[1]]]] - perm[[#2[[2]]]]] > 1]] &, |
|||
Permutations[ |
|||
Range[8]], {{1, 3}, {1, 4}, {1, 5}, {2, 4}, {2, 5}, {2, 6}, {3, |
|||
4}, {3, 7}, {4, 5}, {4, 7}, {4, 8}, {5, 6}, {5, 7}, {5, 8}, {6, |
|||
8}}][[1]]; |
|||
Print[StringForm[ |
|||
" `` ``\n /|\\ /|\\\n / | X | \\\n / |/ \\| \\\n`` - `` \ |
|||
- `` - ``\n \\ |\\ /| /\n \\ | X | /\n \\|/ \\|/\n `` ``", |
|||
Sequence @@ sol]];</lang> |
|||
{{out}} |
|||
<pre> 3 4 |
|||
/|\ /|\ |
|||
/ | X | \ |
|||
/ |/ \| \ |
|||
7 - 1 - 8 - 2 |
|||
\ |\ /| / |
|||
\ | X | / |
|||
\|/ \|/ |
|||
5 6</pre> |
|||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |