From f49aab32e94aad574626c241ce4c85a872d1f0a3 Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine\" Monoids" Date: Tue, 6 Dec 2022 10:26:56 +0300 Subject: [PATCH] day 6: remember that find exists --- 6-a.hs | 5 +++-- 6-b.hs | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/6-a.hs b/6-a.hs index 621e38d..f16ec54 100644 --- a/6-a.hs +++ b/6-a.hs @@ -1,8 +1,9 @@ import Data.List +import Data.Maybe markerLength = 4 main = interact $ show - . (+ 1) . head - . (\l -> filter (\i -> markerLength == length (nub $ map (l !!) [i - (markerLength - 1) .. i])) [(markerLength - 1)..]) \ No newline at end of file + . (+ 1) + . fromJust . (\l -> find (\i -> markerLength == length (nub $ map (l !!) [i - (markerLength - 1) .. i])) [(markerLength - 1)..]) \ No newline at end of file diff --git a/6-b.hs b/6-b.hs index 51a4b93..ce83b31 100644 --- a/6-b.hs +++ b/6-b.hs @@ -1,9 +1,10 @@ import Data.List +import Data.Maybe -- literally only changes this one constant markerLength = 14 main = interact $ show - . (+ 1) . head - . (\l -> filter (\i -> markerLength == length (nub $ map (l !!) [i - (markerLength - 1) .. i])) [(markerLength - 1)..]) \ No newline at end of file + . (+ 1) + . fromJust . (\l -> find (\i -> markerLength == length (nub $ map (l !!) [i - (markerLength - 1) .. i])) [(markerLength - 1)..]) \ No newline at end of file