remove unused index stuff

This commit is contained in:
Rhiannon Morris 2020-12-07 19:45:32 +01:00
parent 58db497e5d
commit 36361b9a7a
1 changed files with 9 additions and 9 deletions

18
day5.ml
View File

@ -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