Created
December 6, 2022 22:01
-
-
Save zoldar/828f2ba72ff5653c43bbfe7ebe2c3476 to your computer and use it in GitHub Desktop.
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
| import std/strformat, std/sets | |
| proc findMarker(input: string, length: int): int = | |
| for idx in 0..<input.len: | |
| if input[idx..<idx+length].toHashSet.len == length: | |
| result = idx + length | |
| break | |
| proc findStartOfPacket*(input: string): int = | |
| findMarker(input, 4) | |
| proc findStartOfMessage*(input: string): int = | |
| findMarker(input, 14) | |
| let input = open("day-6/input.txt").readAll | |
| echo fmt"Start of packet marker position: {findStartOfPacket(input)}" | |
| echo fmt"Start of message marker position: {findStartOfMessage(input)}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment