Created
December 7, 2022 15:48
-
-
Save hovsater/94791daa6c21351f968f8e4fb62557da to your computer and use it in GitHub Desktop.
Solution to Advent of Code 2022, Day 6.
This file contains hidden or 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
module Day06 exposing (partOne, partTwo) | |
import Set exposing (Set) | |
type alias Signal = | |
String | |
findStartOfPacketMarker : Int -> Signal -> Int | |
findStartOfPacketMarker size signal = | |
let | |
helper : Int -> List Char -> Int | |
helper sequenceStart characters = | |
let | |
sequence : Set Char | |
sequence = | |
List.take size characters |> Set.fromList | |
in | |
if not (Set.size sequence == size) then | |
helper (sequenceStart + 1) (List.drop 1 characters) | |
else | |
sequenceStart + size | |
in | |
helper 0 (String.toList signal) | |
partOne : String -> Int | |
partOne = | |
findStartOfPacketMarker 4 | |
partTwo : String -> Int | |
partTwo = | |
findStartOfPacketMarker 14 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment