Skip to content

Instantly share code, notes, and snippets.

@PkmX
Last active August 29, 2015 14:02
Show Gist options
  • Save PkmX/440fc544a18261e4d9f1 to your computer and use it in GitHub Desktop.
Save PkmX/440fc544a18261e4d9f1 to your computer and use it in GitHub Desktop.
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