parent
a770c48d90
commit
6b507bc436
2 changed files with 34 additions and 0 deletions
@ -0,0 +1,29 @@ |
||||
module Day4 |
||||
( |
||||
getNumberOfPasswords |
||||
, getNumberOfPasswords' |
||||
) where |
||||
|
||||
import Data.List |
||||
|
||||
generatePasswords_Part1 :: [Integer] |
||||
generatePasswords_Part1 = |
||||
[ x | x <- [145852..616942] |
||||
, has2Same (show x) |
||||
, increases ((read :: String -> Integer) . (:[]) <$> show x)] |
||||
where |
||||
has2Same xs = let ys = zip xs (tail xs ++ " ") in |
||||
any (uncurry (==)) ys |
||||
increases [] = True |
||||
increases xs = let ys = zip xs (tail xs ++ [maximum xs]) in |
||||
all (uncurry (<=)) ys |
||||
|
||||
getNumberOfPasswords :: Int |
||||
getNumberOfPasswords = length generatePasswords_Part1 |
||||
|
||||
generatePasswords_Part2 :: [Integer] |
||||
generatePasswords_Part2 = filter f generatePasswords_Part1 |
||||
where f x = 2 `elem` (length <$> group (show x)) |
||||
|
||||
getNumberOfPasswords' :: Int |
||||
getNumberOfPasswords' = length generatePasswords_Part2 |
Loading…
Reference in new issue