Add day 6 solutions

This commit is contained in:
Danila Fedorin
2022-12-05 21:47:30 -08:00
parent 07d8457cd8
commit 0aeb0349d7
2 changed files with 40 additions and 0 deletions

17
day6.chpl Normal file
View File

@@ -0,0 +1,17 @@
use IO;
config const numChars = 4;
var theBytes: bytes;
stdin.read(theBytes);
var indices: [0..<26] int = -numChars;
for (char, idx) in zip(theBytes.these() - b"a"[0], 0..) do {
indices[char] = idx;
if + reduce (indices > idx - numChars) == numChars {
writeln(idx + 1);
break;
}
}