Last active
August 29, 2015 14:02
-
-
Save PkmX/440fc544a18261e4d9f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main (main) where | |
import Control.Applicative | |
import qualified Data.Foldable as F | |
import Data.Hashable (Hashable) | |
import qualified Data.HashSet as HS | |
import Linear (V3(..)) | |
import System.Environment (getArgs) | |
type Forest = V3 Int | |
meals :: [Forest] | |
meals = [ V3 (-1) (-1) 1 | |
, V3 (-1) 1 (-1) | |
, V3 1 (-1) (-1) | |
] | |
rmDups :: (Eq a, Hashable a) => [a] -> [a] | |
rmDups = go HS.empty | |
where go _ [] = [] | |
go s (x:xs) = if x `HS.member` s then go s xs | |
else x : go (HS.insert x s) xs | |
solve :: [Forest] -> [Forest] | |
solve fs = if null sol then solve fs' else sol | |
where fs' = rmDups $ fs >>= \f -> filter (F.all (>= 0)) $ map (f +) meals | |
sol = filter ((>= 2) . length . filter (== 0) . F.toList) fs' | |
main :: IO () | |
main = do | |
[g, w, l] <- map read <$> getArgs | |
mapM_ print $ solve [V3 g w l] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment