aboutsummaryrefslogtreecommitdiff
path: root/2022/nim/day06/src/main.nim
blob: cd8eb0a2c43e607e1e8f17d98d7ae983296c6470 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Day 6: Tuning Trouble
import std/[os, strutils, sets]

let input = paramStr(1).readFile().strip().split("\n")[0]

iterator slide(input: string, num: int): string =
  for i in 0 ..< input.len - num:
    var result: string
    for j in 0 ..< num:
      result &= input[i+j]
    yield result

var i = 4
for window in input.slide(4):
  if window.toHashSet.len == 4:
    break
  inc i
echo i

i = 14
for window in input.slide(14):
  if window.toHashSet.len == 14:
    break
  inc i
echo i