aboutsummaryrefslogtreecommitdiff
path: root/0008/main.hs
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-04-09 00:12:32 +0800
committerMistivia <i@mistivia.com>2025-04-09 00:12:32 +0800
commitefcc7ccc3d0c35c9f038a79a63f1592d62ab6652 (patch)
tree7a0022c24a8e7915ad89a87c1f67204442882c02 /0008/main.hs
parent211d23d948fdc42876b76c2724619de8329ff0c0 (diff)
Largest Product in a Series
Diffstat (limited to '0008/main.hs')
-rw-r--r--0008/main.hs13
1 files changed, 13 insertions, 0 deletions
diff --git a/0008/main.hs b/0008/main.hs
new file mode 100644
index 0000000..c852fa7
--- /dev/null
+++ b/0008/main.hs
@@ -0,0 +1,13 @@
+import Data.Char (digitToInt)
+import Data.Maybe (catMaybes)
+
+findMax13 numbers =
+ foldl1 max $ map (\i -> subArrayProduct i 13) [0..((length numbers) - 13)]
+ where
+ subArrayProduct start length =
+ product $ take length (drop start numbers)
+
+main = do
+ contents <- readFile "input"
+ let max13 = findMax13 $ map digitToInt $ filter (\c -> c >= '0' && c <= '9') contents in
+ putStrLn $ show max13