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/09a.hs |
initial commit
Diffstat (limited to '2020/09a.hs')
-rw-r--r-- | 2020/09a.hs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/2020/09a.hs b/2020/09a.hs new file mode 100644 index 0000000..4ee18f2 --- /dev/null +++ b/2020/09a.hs @@ -0,0 +1,24 @@ +module Day9A where + +import System.Environment (getArgs) + +potentialSum :: [Int] -> Int -> [(Int, Int)] +potentialSum xs t = filter ((== t) . uncurry (+)) [(x, y) | x <- xs, y <- xs, x /= y] + +mapSumPrev :: [Int] -> Int -> [[(Int, Int)]] +mapSumPrev xs l = [potentialSum (take l $ drop (i - l) xs) v | (i, v) <- zip [25..] (drop l xs)] + +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 unob = head $ filter (null . fst) $ zip (mapSumPrev xs 25) [25..]; + let unob_n = xs !! snd unob; + putStrLn $ "No way to sum up to " ++ show unob_n; + return (); |