move vec2 into a new file & add a pretty printer
now it shows up properly in utop !!
This commit is contained in:
parent
239af2f93b
commit
5e1c30637e
1
.ocamlinit
Normal file
1
.ocamlinit
Normal file
|
|
@ -0,0 +1 @@
|
|||
#install_printer Aoc.Vec2.pp;;
|
||||
26
src/day8.ml
26
src/day8.ml
|
|
@ -1,28 +1,8 @@
|
|||
open Containers
|
||||
|
||||
module Vec2 : sig
|
||||
type t
|
||||
|
||||
val directions : t list
|
||||
val of_tuple : int * int -> t
|
||||
val to_tuple : t -> int * int
|
||||
val ( + ) : t -> t -> t
|
||||
val at : 'a array array -> t -> 'a option
|
||||
end = struct
|
||||
type t = int * int
|
||||
|
||||
let directions = [ 1, 0; 0, 1; -1, 0; 0, -1 ]
|
||||
let of_tuple x = x
|
||||
let to_tuple x = x
|
||||
let ( + ) a b = Pair.map_same2 ( + ) a b
|
||||
|
||||
let at grid point =
|
||||
let x, y = to_tuple point in
|
||||
let open Option.Infix in
|
||||
let* row = Array.get_safe grid y in
|
||||
Array.get_safe row x
|
||||
;;
|
||||
end
|
||||
(* module Vec2 : sig *)
|
||||
(* end = struct *)
|
||||
(* end *)
|
||||
|
||||
let parse_grid () =
|
||||
let lines = Utils.lines_of_input 8 in
|
||||
|
|
|
|||
2
src/dune
2
src/dune
|
|
@ -1,7 +1,7 @@
|
|||
(library
|
||||
(name aoc)
|
||||
(libraries re containers dune-site)
|
||||
(preprocess (pps ppx_regexp)))
|
||||
(preprocess (pps ppx_regexp ppx_deriving.show)))
|
||||
|
||||
(env
|
||||
(dev
|
||||
|
|
|
|||
21
src/vec2.ml
Normal file
21
src/vec2.ml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
open Containers
|
||||
|
||||
type t = int * int [@@deriving show]
|
||||
|
||||
let up = 0, 1
|
||||
let down = 0, -1
|
||||
let left = -1, 0
|
||||
let right = 1, 0
|
||||
let directions = [ up; down; left; right ]
|
||||
let of_tuple x = x
|
||||
let to_tuple x = x
|
||||
let ( + ) a b = Pair.map_same2 ( + ) a b
|
||||
let ( - ) a b = Pair.map_same2 ( - ) a b
|
||||
let ( = ) a b = Pair.equal ( = ) ( = ) a b
|
||||
|
||||
let at grid point =
|
||||
let x, y = to_tuple point in
|
||||
let open Option.Infix in
|
||||
let* row = Array.get_safe grid y in
|
||||
Array.get_safe row x
|
||||
;;
|
||||
13
src/vec2.mli
Normal file
13
src/vec2.mli
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
type t [@@deriving show] [@@ocaml.toplevel_printer]
|
||||
|
||||
val up : t
|
||||
val down : t
|
||||
val left : t
|
||||
val right : t
|
||||
val directions : t list
|
||||
val of_tuple : int * int -> t
|
||||
val to_tuple : t -> int * int
|
||||
val ( + ) : t -> t -> t
|
||||
val ( - ) : t -> t -> t
|
||||
val ( = ) : t -> t -> bool
|
||||
val at : 'a array array -> t -> 'a option
|
||||
Loading…
Reference in New Issue
Block a user