data Position = Shoe | Skirt | Chest | Hair deriving (Show, Eq, Ord)
solve :: [String] solve = do -- ちょうど一万円札・千円札・百円玉・十円玉があるわ。今からこのお金を・・・ let money = [10000, 1000, 100, 10] -- 髪の中、胸のポケット、スカートのポケット、靴の中に・・・それぞれ一つずつ隠します (position, content) <- mappings money [Hair, Chest, Skirt, Shoe] -- 一万円札は髪の中 guard $ position 10000 == Hair -- 千円札は十円玉より上の位置 guard $ position 1000 > position 10 -- スカートには胸の10倍のお金が入っている guard $ content Skirt == 10 * content Chest -- それでは、全てのお金の位置は? let disp n = show (position n) ++ "(" ++ show n ++ ")" return $ unwords $ map disp money
main = putStr $ unlines solve
mappings :: (Eq a, Eq b) => [a] -> [b] -> [(a -> b, b -> a)] mappings xs ys = do ys' <- permutations ys return (make xs ys', make ys' xs) where make from to = \value -> case lookup value (zip from to) of Just r -> r Nothing -> error "lookup failed"