blob: 5df694171a2d0a058102e90ad16db2c8a1539e74 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
module Day10A where
import System.Environment (getArgs)
import Data.List (sort)
-- Get the longest chain of adapters possible
getJoltsChain :: [Int] -> [Int]
getJoltsChain ss = xs ++ [last xs + 3]
where xs = sort ss
-- Read a line-seperated file of numbers
numsFromFile :: String -> IO [Int]
numsFromFile p = do
c <- readFile p;
return $ map read $ lines c;
main :: IO ()
main = do
args <- getArgs;
xs <- numsFromFile $ head args;
let chain = 0 : getJoltsChain xs;
let diffs = zipWith (-) chain (drop 1 chain);
let diff3s = length $ filter (== -3) diffs;
let diff1s = length $ filter (== -1) diffs;
print $ diff1s * diff3s;
return ();
|