{- Построить фигуру, не отрывая письменной принадлежности от бумаги и не проводя одну и ту же линию дважды 1 / \ 2---3 /|\ /|\ 4 | 5 | 6 \|/ \|/ 7---8 \ / 9 -} ps = [ (1,2) , (1,3) , (2,3) , (2,4) , (2,5) , (2,7) , (3,5) , (3,6) , (3,8) , (4,7) , (5,7) , (5,8) , (6,8) , (7,8) , (7,9) , (8,9) ] getLongest (x:[]) = x getLongest (x:xs) = let y = getLongest xs in if (length x) > (length y) then x else y possibleMoves x = [fst m | m <- ps, (snd m) == x] ++ [snd m | m <- ps, (fst m) == x] makeMove x y = if (x < y) then (x,y) else (y,x) makeMovesList :: (Integral a) => [a] -> [(a,a)] makeMovesList (x:y:ys) = [makeMove x y] ++ (makeMovesList (y:ys)) makeMovesList _ = [] makePath [] = getLongest [path | path <- [makePath [x] | x <- [1..9]]] makePath xs = let xt = (last xs) in let ps = [x | x <- (possibleMoves xt), not ((makeMove x xt) `elem` (makeMovesList xs))] in -- ps — все возможные ходы, исключая уже сделанные if (null ps) then xs else (getLongest [makePath (xs ++ [p]) | p <- ps]) main = print (makePath [])