Haskell 河内塔-移动列表,检查是否有效

Haskell 河内塔-移动列表,检查是否有效,haskell,functional-programming,towers-of-hanoi,Haskell,Functional Programming,Towers Of Hanoi,我正在Haskell的编程任务中挣扎。 我必须写一个函数: move::([move],Towers)->([move],Towers) 它包含一个移动列表和一个游戏配置。函数必须检查第一步是否有效,然后执行该步。下面您可以看到该函数的可能输出。我是Haskell的新手,这个编程任务对我来说意义重大。我不知道该从哪里开始。解决这个问题的基本策略是什么。我真的很想学,如果你能给我一些建议,我会很高兴的 谢谢 type Position = Int type Move = (Positi

我正在Haskell的编程任务中挣扎。 我必须写一个函数:

move::([move],Towers)->([move],Towers)

它包含一个移动列表和一个游戏配置。函数必须检查第一步是否有效,然后执行该步。下面您可以看到该函数的可能输出。我是Haskell的新手,这个编程任务对我来说意义重大。我不知道该从哪里开始。解决这个问题的基本策略是什么。我真的很想学,如果你能给我一些建议,我会很高兴的

谢谢

 type Position = Int
 type Move     = (Position,Position)
 type Towers   = ([Int],[Int],[Int])

 hanoi :: Int -> Position -> Position -> [Move]
 hanoi 1 i j = [(i, j)]
 hanoi n i j = (hanoi (n-1) i other) ++ [(i, j)] ++ (hanoi (n-1) other j)
     where
        other = 1+2+3-i-j
输出:
move::([move],Towers)->([move],Towers)

move::([move],塔)->([move],塔)
移动([],t)=([],t)
移动(x:xs,t)=移动(xs,move1 x t)
移动1::移动->塔->塔
动议1(i,j)(a,b,c)
|i==1&&j==2&¬(null a)=如果inf a b那么(尾部a,头部a:b,c)否则错误“磁盘太大”
|i==1&&j==3&¬(null a)=如果是inf a c,那么(尾部a、b、头部a:c)否则错误“磁盘太大”
|i==2&&j==1&¬(null b)=如果inf b a那么(头b:a,尾b,c)否则错误“磁盘太大”
|i==2&&j==3&¬(null b)=如果inf b c那么(a,尾部b,头部b:c)否则错误“磁盘太大”
|i==3&&j==1&¬(null c)=如果inf c a那么(头c:a,b,尾c)否则错误“磁盘太大”
|i==3&&j==2&¬(null c)=如果inf c b那么(a,头c:b,尾c)否则错误“磁盘太大”
|否则=错误“移动无效”
inf::[Int]->[Int]->Bool
inf a b=空b | |头a<最小值b

我想我在什么地方见过这个。。。。但实际上:在没有实现上述功能的情况下,如何获得
move
的输出?你的问题到底在哪里?我真的很难理解这里的问题。这是函数输出的一个例子。在我看来,好像你一次移动了整个塔-解决方案似乎很简单,谢谢,但这是一次移动所有光盘。该功能应该只是把光盘放在上面…我的坏,我们应该只是移动列表的头。
> hanoi 3 1 3 [(1,3),(1,2),(3,2),(1,3),(2,1),(2,3),(1,3)]
> move (it, ([1,2,3],[],[])) ([(1,2),(3,2),(1,3),(2,1),(2,3),(1,3)],([2,3],[],[1])) 
> move it ([(3,2),(1,3),(2,1),(2,3),(1,3)],([3],[2],[1]))
> move it ([(1,3),(2,1),(2,3),(1,3)],([3],[1,2],[]))
> move ([(1,4)],([3],[1,2],[])) ([],*** Exception: Move not valid!
> move ([(1,2),(1,3)],([3,4],[1,2],[])) ([(2,3)],([4],*** Exception: Disc is to big!
move ::([Move],Towers) -> ([Move],Towers)
move ([],t) = ([],t)
move (x:xs,t) = move (xs,move1 x t)

move1::Move->Towers->Towers
move1 (i,j) (a,b,c)
    | i==1 && j==2 && not (null a) = if inf a b then (tail a,head a:b,c) else error "Disk too large"
    | i==1 && j==3 && not (null a) = if inf a c then (tail a,b,head a:c) else error "Disk too large"
    | i==2 && j==1 && not (null b) = if inf b a then (head b:a,tail b,c) else error "Disk too large"
    | i==2 && j==3 && not (null b) = if inf b c then (a,tail b,head b:c) else error "Disk too large"
    | i==3 && j==1 && not (null c) = if inf c a then (head c:a,b,tail c) else error "Disk too large"
    | i==3 && j==2 && not (null c) = if inf c b then (a,head c:b,tail c) else error "Disk too large"
    | otherwise = error "Move not valid"

inf :: [Int]->[Int]->Bool
inf a b = null b || head a < minimum b