diff --git a/day5.ml b/day5.ml index 7f7c403..2873583 100644 --- a/day5.ml +++ b/day5.ml @@ -9,34 +9,34 @@ let rec find' ?(lo=0) ~hi = function | L::hs -> find' ~lo ~hi:(avg lo hi) hs | H::hs -> find' ~lo:(avg (lo+1) hi) ~hi hs -exception Inexact of bounds * int option [@warn_on_literal_pattern] +exception Inexact of bounds [@warn_on_literal_pattern] -let find ?index ?lo ~hi halves = +let find ?lo ~hi halves = match find' ?lo ~hi halves with | Exact x -> x - | Between p -> raise (Inexact (p, index)) + | Between p -> raise (Inexact p) type path = {rows: half list; cols: half list} -exception Unknown_char of char * int option +exception Unknown_char of char [@warn_on_literal_pattern] -let path_of_string ?index str = +let path_of_string str = let revs {rows; cols} = List.{rows = rev rows; cols = rev cols} in let put acc = function | 'F' -> {acc with rows = L :: acc.rows} | 'B' -> {acc with rows = H :: acc.rows} | 'L' -> {acc with cols = L :: acc.cols} | 'R' -> {acc with cols = H :: acc.cols} - | c -> raise (Unknown_char (c, index)) in + | c -> raise (Unknown_char c) in String.to_seq str |> Seq.fold_left put {rows = []; cols = []} |> revs type seat = {row: int; col: int} -let seat_of_path ?index {rows; cols} = - {row = find ?index ~hi:127 rows; - col = find ?index ~hi:7 cols} +let seat_of_path {rows; cols} = + {row = find ~hi:127 rows; + col = find ~hi:7 cols} let seat_id {row; col} = (row * 8) + col