diff --git a/Makefile b/Makefile index 72623ad..f3b3462 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -DAY = 2 +DAY = 3 DIR = day$(DAY) diff --git a/day3/input.txt b/day3/input.txt new file mode 100644 index 0000000..02370bf --- /dev/null +++ b/day3/input.txt @@ -0,0 +1,300 @@ +GwrhJPDJCZFRcwfZWV +LjnQlqNpjjmpmQlLlqNfZRvQcTWcTSTTZcSQcZ +nNqjdspspngnmjmslqmjjjCDGrHPHMGddGCMCGPPPJWC +GwmVZmPWWFFmBbVbZVwmbPsTCnlgQgnQfhlffffZnlQh +DqVDSqqSMzLLDDNSHHLdqSdSllCQjsTlClhlflnTlhjgfgfM +VHJztNLHGtcbvvPG +bjrPrNCtNrjdcCPpptfpTVspDtfTtB +JGQJMJQMmmmZMnnLpLBTpHCD +WJJqWRgWlCJZhZRCQZwdPScdrPNbvzPzwvqz +QNSQNBWQNLjZBNNhLhSNRsTcsrTTVzcwZZZsfrrbwb +tCFtHpppppMldpvpqnMFmMVGrbPcrwbzswrzcccfvTfw +pdmCpgqCdmHHdJVWgSRNJDRVVj +sNrFnvNSzrjQtQjQTj +lcPmcJDLdPDbJPVLljdGGBBThBQTGwTtBw +PDLqmJmpJQfFqfqsCM +BnhctqdnqnRcBnslCJJCMrJrsG +wNDMZpbQwMpCvCGVjlss +WfzNwZFbwZzZmFZbLzNwzzzzcdqgRMTTPdHPTTPMRdcWgRPt +grsrVSFSSdFSDFVFjZZWwpWpZWZplgZZ +mcBPPPBLBfNdLlvvWljWJC +dMcmcRdbRzdVhFthSsTShM +bzvJZMTzTZSHLCCdDzmDcc +hqBqWPFssvshWvvssNqtsHftmfpHfdcdDGHmcpfctL +WvBQgNNNhghTJbJQlJTZlT +chcdwNwdbCbQctCjnnQGHsQspMHMjG +nSSSJqJZzJgWWRfZDJSnqvTTsVvvHVPpHVfpjHMTjP +BZRDRmmrDWSrZWWzWSRNhdnCFwChclFtwbNdtr +lNgmssCtqLwqCCtfsCLHPF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JJVbSSRVZwwJcmpWDGCWnbchnLCCmnWCG +llSJzsZzMMlsSZjSjZwJNQqtHHdBFsqdfTHhqFftQB +zdTJFHTdDBzrNdMnhNnNdM +ZlLZZcLtVtcWtGjtzLjLZjCrnVNrnRbrQQbQSRVrRnSNqS +lZtGtCvjZPCGCctPpsDDBzTHFmPmFszD +mQSMvdMQtQdZhQrPWCPqPQrN +RwjwnZGzJFTZgzggzJDDwJnCPPhNNqPrLhrGNcWcWNPqCq +ZTzDfnwFzTngTwJvfSlMtMMlmsHmHt +lZlmFRVZWmgQWhRsRpJsCJpJct +PTbPTGTGwwGrbdfjNNZJvcCsCZtvpTsh +bGdBBqGrdBPjDMzzVFZgqQzFFL +szvsmLvppPPtzGLGWpVdTSHTNgjHQRmHTgSH +FnBMBNZwZNcnDZMcnZlZgwgdQTTHjVJjHHVRQHJj +DnZrFCMZMNffrLPbLsfW +rJvmnBgnrCrGRSGNQR +hthjNfhwctwpjTLtVLjTGSpldSCGSPdlPSRzSqSz +TVcTfHNFcwtjMhTvgbHZsBbWmmZbnH +WsQgstQmvQJnssWsWPzhRzhBjZBSBRZSnj +qwCNqFwDrrlDrFPvRhTSPPzLRz +bppqwppCddlvfbDNVgmMmtMfVVmfmVWW diff --git a/day3/main.hs b/day3/main.hs new file mode 100644 index 0000000..33faffd --- /dev/null +++ b/day3/main.hs @@ -0,0 +1,48 @@ +import System.IO + +import Data.Char (ord) + +import Data.Set (Set) +import qualified Data.Set as Set + +import Data.List.Split + + + +itemprio :: Char -> Int +itemprio c + | 'a' <= c && c <= 'z' = ord c - ord 'a' + 1 + | 'A' <= c && c <= 'Z' = ord c - ord 'A' + 27 + + + +duplitems :: Ord a => [a] -> [a] -> [a] +duplitems c1 c2 = Set.elems $ Set.intersection s1 s2 + where s1 = (Set.fromList c1) + s2 = (Set.fromList c2) + + + +splitEqual :: Int -> [a] -> [[a]] +splitEqual n x = chunksOf (length x `div` n) x + + + +rsprio :: String -> Int +rsprio x = itemprio $ head $ duplitems (head rs) (last rs) + where rs = splitEqual 2 x + + + +grpprio :: [String] -> Int +grpprio = itemprio . head . foldr1 duplitems + + + +handler :: String -> String +handler s = (show $ sum $ map rsprio $ lines s) ++ "\n" ++ + (show $ sum $ map grpprio $ chunksOf 3 $ lines s) ++ "\n" + +main :: IO () +main = do + interact handler