Compare commits
No commits in common. "bb8075b0c05ef1bd3862bcdda6832ee0d59fe41a" and "70a14bd150813a3ad4e751c29ea13892179c6d74" have entirely different histories.
bb8075b0c0
...
70a14bd150
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
input.txt
|
|
2265
day1/input.txt
Normal file
2265
day1/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
2500
day2/input.txt
Normal file
2500
day2/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
48
day3/main.hs
48
day3/main.hs
@ -1,48 +0,0 @@
|
|||||||
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
|
|
Loading…
x
Reference in New Issue
Block a user