git.haldean.org aoc-2018 / cf5d45a
pretty pretty pretty Haldean Brown 1 year, 4 days ago
1 changed file(s) with 12 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
00 import Control.Arrow
11 import Data.Char
22 import Data.Function
3 import qualified Data.List as L
4 import qualified Data.Set as S
5 import System.Environment
36
47 collapse1 (a:b:ss)
58 | toLower a == toLower b && a /= b = collapse1 ss
69 | otherwise = a:(collapse1 $ b:ss)
710 collapse1 s = s
811 collapse s = let cs = collapse1 s in if cs == s then s else collapse cs
9 main = readFile "input.txt" >>= (collapse >>> length >>> subtract 1 >>> print)
12 main1 = readFile "input.txt" >>= (collapse >>> length >>> subtract 1 >>> print)
13
14 minimize s =
15 let units = S.fromList $ map toLower s
16 in S.map (\u -> filter ((u /=) . toLower) s & collapse & length) units
17 & S.toList & L.minimum & subtract 1
18 main2 = readFile "input.txt" >>= (collapse >>> minimize >>> print)
19
20 main = fmap head getArgs >>= \a -> if a == "1" then main1 else main2