diff options
author | Aria <me@aria.rip> | 2023-01-02 21:58:56 +0000 |
---|---|---|
committer | Aria <me@aria.rip> | 2023-01-02 21:58:56 +0000 |
commit | 5eb58ad076f2cd435b11b140820da224b60b73d5 (patch) | |
tree | 2a67939595fbf993ff04f69b9cd3f0aa20827d96 /2020/10a.hs |
initial commit
Diffstat (limited to '2020/10a.hs')
-rw-r--r-- | 2020/10a.hs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/2020/10a.hs b/2020/10a.hs new file mode 100644 index 0000000..5df6941 --- /dev/null +++ b/2020/10a.hs @@ -0,0 +1,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 (); |