pull/1/head
Gaël Depreeuw 5 years ago
parent a770c48d90
commit 6b507bc436
  1. 5
      app/Main.hs
  2. 29
      src/Day4.hs

@ -3,6 +3,7 @@ module Main where
import Day1 import Day1
import Day2 import Day2
import Day3 import Day3
import Day4
import System.IO import System.IO
import Data.List.Split import Data.List.Split
import Data.Set import Data.Set
@ -41,4 +42,8 @@ main = do
r_day3 <- readFile "./app/input_day3" r_day3 <- readFile "./app/input_day3"
putStr "[Day 3] Result: " putStr "[Day 3] Result: "
print $ getDistanceAndSteps r_day3 print $ getDistanceAndSteps r_day3
putStr "[Day 4-1] Result: "
print getNumberOfPasswords
putStr "[Day 4-2] Result: "
print getNumberOfPasswords'

@ -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…
Cancel
Save