Created
December 3, 2017 03:06
-
-
Save frenata/f29f20f9be66cdcdac049f80086edfbd 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 Data.Char | |
import Data.Monoid | |
zipRot :: Int -> [a] -> [(a, a)] | |
zipRot n xs = | |
let rotXs = (drop n xs) ++ (take n xs) | |
in zip xs rotXs | |
captcha :: (Monoid a, Eq a) => Int -> [a] -> a | |
captcha n xs = | |
foldr | |
(\(x, y) acc -> | |
if x == y | |
then acc <> x | |
else acc) | |
mempty $ | |
zipRot n xs | |
toSum :: Char -> Sum Int | |
toSum c = Sum $ read [c] | |
main :: IO () | |
main = do | |
file <- readFile "data.txt" | |
let trimFile = takeWhile isDigit file | |
let sums = toSum <$> trimFile | |
--putStrLn . show . captcha 1 $ sums | |
putStrLn . show . captcha (length trimFile `div` 2) $ sums |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment