油売り算(失敗)

30分プログラム、その116。油売り算をやろうとして失敗した。
小町算も失敗しているし、苦手なのかなぁ。

そもそもの方法が間違っている気もするけど、一応ソースコードを貼っておく。
そのうち、再チェレンジしよう。

ソースコード

import Data.List

data Cup = Cup { name :: String , size :: Int , amount::Int} deriving (Eq,Show)

isOK xs = or $ do x <- xs'
                  y <- delete x xs'
                  let zs = delete y $ delete x xs'
                  return $ x == y && (and $ map (==0) zs)
    where xs' = map amount xs

move from to = let (a,b) = if space to > amount from 
                           then (0,amount to + amount from)
                           else (amount from - space to,size to)
               in (from{amount=a},to{amount=b})
    where space (Cup {amount=amount,size=size}) = size - amount

abura xs = if isOK xs then [[]]
           else do from <- xs
                   to <- delete from xs
                   let rest = delete to $ delete from xs
                   let (from',to') = move from to
                   rest' <- abura $ from':to':rest
                   return $ (from,to):rest'

a = Cup {name="A", size=10,amount=10}
b = Cup {name="B", size=7,amount=0}
c = Cup {name="B", size=3,amount=0}

a' = Cup {name="A'", size=10,amount=5}
b' = Cup {name="B'", size=7,amount=5}