diff --git a/2022/day6.nim b/2022/day6.nim index a23171d..9cd4c5a 100644 --- a/2022/day6.nim +++ b/2022/day6.nim @@ -34,10 +34,26 @@ proc find_first(n: int, skip: int = 0): int = return i return -1 +proc string_no_duplicate_chars_copyless(s: string, i: int, n: int): bool = + # 1M iterations: nim r -d:danger day6.nim 22.70s user 0.13s system 97% cpu 23.412 total + let lower = i-n+1 + for j in countdown(i, lower+1): + let c = s[j] + for k in countdown(j-1, lower): + if c == s[k]: + return false + return true + +proc find_first_copyless(n: int, skip: int = 0): int = + for i in max(n, skip)..