Skip to content

Instantly share code, notes, and snippets.

@frenata
Created December 3, 2017 03:06
Show Gist options
  • Save frenata/f29f20f9be66cdcdac049f80086edfbd to your computer and use it in GitHub Desktop.
Save frenata/f29f20f9be66cdcdac049f80086edfbd to your computer and use it in GitHub Desktop.
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