-
-
Save dminuoso/cf4ffb90aa48c82cf8e4946e941c5940 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
findMarker :: Int -> Int -> Int -> BS.ByteString -> Int | |
findMarker l o n buf = do | |
case BS.elemIndexEnd c window of | |
Nothing | o <= 0 -> n | |
| otherwise -> findMarker l (o - 1) (n + 1) buf | |
Just i -> let o' = max i (o - 1) | |
in findMarker l o' (n + 1) buf | |
where | |
c = BS.index buf (n - 1) | |
window = BS.take windowW (BS.drop windowL buf) | |
windowW = min l n - 1 | |
windowL = max (n - l) 0 | |
main = do | |
buf <- BS.readFile "day6/input.txt" | |
let l = 14 | |
print (findMarker l 14 1 buf) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment