adventOfCode/challenges/2022/06-tuningTrouble/nim/challenge.nim
AKP 5c61b3acfb
2022-06 py,nim & 2022-05 nim
Signed-off-by: AKP <tom@tdpain.net>
2022-12-06 09:43:49 +00:00

11 lines
396 B
Nim

import std/sets
proc find_unique_sequence(instr: string, length: int): int =
for i in countup(0, instr.len - length):
if toHashSet(instr[i..<i+length]).len == length:
return i+length
raise newException(ValueError, "cannot solve")
proc partOne*(instr: string): int = find_unique_sequence(instr, 4)
proc partTwo*(instr: string): int = find_unique_sequence(instr, 14)