module Problem90 where

import Control.Monad
import Data.List

main :: IO ()
main = print . length $ filter
    squarePossible
    [ (x, y) | x <- subsets, y <- subsets, show (sort x) < show (sort y) ]
  where
    subsets =
        map (\xs -> if (6 `elem` xs) || (9 `elem` xs) then 6 : 9 : xs else xs)
            . filter (\xs -> length xs == 6)
            $ filterM (const [True, False]) [0 .. 9]
    squarePossible (s1, s2) = all
        (contained (s1, s2) . ((\x -> [x `div` 10, x `mod` 10]) . (\x -> x * x)))
        [1 .. 9]
    contained (s1, s2) [a, b] =
        (a `elem` s1 && b `elem` s2) || (b `elem` s1 && a `elem` s2)
