Skip to content

Instantly share code, notes, and snippets.

@mjgpy3
Created December 2, 2020 22:11
Show Gist options
  • Select an option

  • Save mjgpy3/efe0ca57d60c279ea8e1d1c461fd40ff to your computer and use it in GitHub Desktop.

Select an option

Save mjgpy3/efe0ca57d60c279ea8e1d1c461fd40ff to your computer and use it in GitHub Desktop.
aoc-2019-d4p2.hs
module D4 where
import Control.Monad (guard)
import Data.List (group)
s = 147981
e = 691423
exTwoAdj = elem 2 . map length . group . show
notDecr = go . show
where
go (x:y:rest) = x <= y && go (y:rest)
go [x] = True
go _ = False
possible = do
v <- [s..e]
guard $ exTwoAdj v && notDecr v
pure v
main = print $ length possible
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment