aboutsummaryrefslogtreecommitdiff
path: root/2022/nim
diff options
context:
space:
mode:
authorj-james2022-12-06 06:54:35 +0000
committerj-james2022-12-06 06:54:35 +0000
commit216616ab804a9b8df86511f356f692db5406d654 (patch)
tree9e01ee175059e2bc76ce94c55d9685139c0e9fc5 /2022/nim
parentfbf08093a62a6c99e14df0b001d4acc5459e8e06 (diff)
Day Six
Diffstat (limited to '2022/nim')
-rw-r--r--2022/nim/day06/src/main.nim25
1 files changed, 25 insertions, 0 deletions
diff --git a/2022/nim/day06/src/main.nim b/2022/nim/day06/src/main.nim
new file mode 100644
index 0000000..cd8eb0a
--- /dev/null
+++ b/2022/nim/day06/src/main.nim
@@ -0,0 +1,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