summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBrian Chu <brianmchu42@gmail.com>2022-12-05 21:23:25 -0800
committerBrian Chu <brianmchu42@gmail.com>2022-12-05 21:23:25 -0800
commit0f4c87139ea2099d000d59ab0acf9307011a9af0 (patch)
treed99c621a9159beceba3c035ebd9d0567e9dfc542
parentaf2b874eb5cf4d173a1b90d90e730352b7d599cd (diff)
downloadAdventOfCode2022-0f4c87139ea2099d000d59ab0acf9307011a9af0.tar.gz
solution for day 6
-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