day06: handle no match

This commit is contained in:
Rupus Reinefjord 2022-12-06 19:27:24 +01:00
parent 93c1db7b57
commit d04337ce03

View file

@ -1,11 +1,12 @@
proc decode(data: string, unique: int): int =
for i in 0..data.high:
for i in 0..data.len - unique:
block inner:
let chars = data[i..i + unique - 1]
for j in 0..unique - 2:
if chars[j] in chars[j+1..^1]:
break inner
return i + unique
return -1
let data = stdin.readAll()
echo decode(data, 4)