Solve the no connection puzzle: Difference between revisions
Content added Content deleted
(Added Mathematica) |
(Added Haskell version) |
||
Line 498: | Line 498: | ||
Tested 12094 positions and did 20782 swaps. |
Tested 12094 positions and did 20782 swaps. |
||
</pre> |
</pre> |
||
=={{header|Haskell}}== |
|||
<lang haskell>import Data.List |
|||
isSolution :: [Int] -> Bool |
|||
isSolution (a:b:c:d:e:f:g:h:_) = |
|||
all (\v -> abs v > 1) |
|||
[a-d, |
|||
c-d, |
|||
g-d, |
|||
e-d, |
|||
a-c, |
|||
c-g, |
|||
g-e, |
|||
e-a, |
|||
b-e, |
|||
-- d-e > 1 && |
|||
h-e, |
|||
f-e, |
|||
b-d, |
|||
d-h, |
|||
h-f, |
|||
f-b] |
|||
main :: IO () |
|||
main = do |
|||
let solution@(a:b:c:d:e:f:g:h:_) = head $ filter isSolution (permutations [1..8]) |
|||
mapM_ putStrLn $ zipWith (\label val -> [label] ++ " = " ++ show val) ['A'..'H'] solution |
|||
putStrLn "" |
|||
putStrLn $ " " ++ (show a) ++ " " ++ (show b) |
|||
putStrLn $ (show c) ++ " " ++ (show d) ++ " " ++ (show e) ++ " " ++ (show f) |
|||
putStrLn $ " " ++ (show g) ++ " " ++ (show h) |
|||
</lang> |
|||
{{out}} |
|||
<pre style="font-size:80%">A = 3 |
|||
B = 4 |
|||
C = 7 |
|||
D = 1 |
|||
E = 8 |
|||
F = 2 |
|||
G = 5 |
|||
H = 6 |
|||
3 4 |
|||
7 1 8 2 |
|||
5 6 </pre> |
|||