From 8d7aedcc3922f27cafbb70ee6e4e0a150c126efc Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Tue, 6 Dec 2022 23:19:48 +1030 Subject: [PATCH] Nim's last stand --- 2022/day6.nim | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) 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)..