summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--Program.fs2
-rw-r--r--solutions/day6.fs20
2 files changed, 22 insertions, 0 deletions
diff --git a/Program.fs b/Program.fs
index d79e29e..f132094 100644
--- a/Program.fs
+++ b/Program.fs
@@ -18,5 +18,7 @@ match (day, part) with
 | (4, 2) -> printf $"{Day4.part2 ()}\n"
 | (5, 1) -> printf $"{Day5.part1 ()}\n"
 | (5, 2) -> printf $"{Day5.part2 ()}\n"
+| (6, 1) -> printf $"{Day6.part1 ()}\n"
+| (6, 2) -> printf $"{Day6.part2 ()}\n"
 | (x, y) when (1 <= x && x <= 25) && (y = 1 || y = 2)  -> raise (NotImplemented("not implemented yet"))
 | _ -> raise (NotImplemented("invalid values"))
\ No newline at end of file
diff --git a/solutions/day6.fs b/solutions/day6.fs
new file mode 100644
index 0000000..bb83388
--- /dev/null
+++ b/solutions/day6.fs
@@ -0,0 +1,20 @@
+namespace Solutions
+
+module Day6 =
+    open System.IO
+
+    let buf = File.ReadAllText("inputs/day6.txt")
+
+    let rec scan size str index =
+        if String.length str < size then -1
+        else
+            let current = str[..size - 1] |> Set.ofSeq
+            if Set.count current = size then index + size
+            else
+                scan size str[1..] index + 1
+
+    let part1 () =
+        scan 4 buf 0
+
+    let part2 () =
+        scan 14 buf 0
\ No newline at end of file