solved day 6 !
This commit is contained in:
1 parent
f31499ecda
commit
45d735bac9
3 files changed
+34
-1
No files matched your search
+31
@@ -0,0 +1,31 @@
|
||||
open Containers
|
||||
module CharSet = Set.Make (Char)
|
||||
|
||||
let window = 4
|
||||
|
||||
let stream =
|
||||
match Utils.lines_of_input 6 with
|
||||
| [ line ] -> line
|
||||
| _ -> failwith "more than one line in input"
|
||||
;;
|
||||
|
||||
let find_start window =
|
||||
let length = String.length stream in
|
||||
let start_index =
|
||||
List.Infix.(0 --^ (length - window))
|
||||
|> List.drop_while (fun index ->
|
||||
let chunk = String.take window (String.drop index stream) in
|
||||
window <> (chunk |> String.to_list |> CharSet.of_list |> CharSet.cardinal))
|
||||
|> List.hd
|
||||
in
|
||||
start_index + window
|
||||
;;
|
||||
|
||||
let part1 () = find_start 4
|
||||
let part2 () = find_start 14
|
||||
|
||||
let print () =
|
||||
Printf.(
|
||||
printf "Day 6.1: %d\n" @@ part1 ();
|
||||
printf "Day 6.2: %d\n" @@ part2 ())
|
||||
;;
|
||||
Reference in new issue
Block a user