Haskell:
module Main where import Data.List (sort) import Data.Maybe (listToMaybe) import Data.Bool (bool) import Control.Arrow ((&&&)) decode :: String -> Int decode = foldl (\n a -> (bool 0 1 . (`elem` "BR") $ a) + 2*n) 0 parseInput :: String -> [Int] parseInput = fmap decode . lines distanceOf :: (Ord a, Num a) => a -> [a] -> [(a, a)] distanceOf n l = [ (x, y) | (x,y) <- (zip <*> tail) . sort $ l, abs (x - y) == n ] solveP1 :: [Int] -> Int solveP1 = maximum solveP2 :: [Int] -> Maybe Int solveP2 = fmap (succ . fst) . listToMaybe . distanceOf 2 main :: IO () main = print . (solveP1 &&& solveP2) . parseInput =<< readFile "./day5inp.txt"
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Haskell: