From 018d194796c85a5b4e665f2668c984dbac7b8537 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Sat, 10 Dec 2022 18:50:02 +0100 Subject: [PATCH] start with three --- .gitignore | 1 + three.hs | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 .gitignore create mode 100644 three.hs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0721bc5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +!*.hs diff --git a/three.hs b/three.hs new file mode 100644 index 0000000..dcc0e05 --- /dev/null +++ b/three.hs @@ -0,0 +1,15 @@ + +splitlist :: [a] -> ([a],[a]) +splitlist list = (take n list,drop n list) + where n = (length list) `div` 2 + +inBoth :: (Eq a) => ([a],[a]) -> [a] +inBoth (first,second) = do + inFirst <- first + if (inFirst `elem` second) then return inFirst else [] + + + +main = do + input <- readFile "three-input.txt" + print $ map ( inBoth . splitlist ) $ lines input