Created
December 3, 2022 22:22
-
-
Save evinism/6868d8fcdd3c47f441a3f2c21b3488f8 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
import qualified Data.Set as Set | |
import Data.Char | |
main = do | |
input <- readFile "input.txt" | |
print $ fn input | |
fn :: String -> Int | |
fn = sum . (fmap procline) . lines | |
procline :: String -> Int | |
procline line = sum $ fmap scorechar $ Set.toList intersection | |
where | |
left = Set.fromList $ take ((length line) `div` 2) line | |
right = Set.fromList $ drop ((length line) `div` 2) line | |
intersection = Set.intersection left right | |
scorechar :: Char -> Int | |
scorechar c = | |
if c >= 'a' | |
then | |
(ord c) - (ord 'a') + 1 | |
else | |
(ord c) - (ord 'A') + 27 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment