move vec2 into a new file & add a pretty printer
now it shows up properly in utop !!
This commit is contained in:
1 parent
239af2f93b
commit
5e1c30637e
5 files changed
+39
-24
No files matched your search
@@ -0,0 +1 @@
|
|||||||
|
#install_printer Aoc.Vec2.pp;;
|
||||||
+3
-23
@@ -1,28 +1,8 @@
|
|||||||
open Containers
|
open Containers
|
||||||
|
|
||||||
module Vec2 : sig
|
(* module Vec2 : sig *)
|
||||||
type t
|
(* end = struct *)
|
||||||
|
(* end *)
|
||||||
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
|
|
||||||
|
|
||||||
let parse_grid () =
|
let parse_grid () =
|
||||||
let lines = Utils.lines_of_input 8 in
|
let lines = Utils.lines_of_input 8 in
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
(library
|
(library
|
||||||
(name aoc)
|
(name aoc)
|
||||||
(libraries re containers dune-site)
|
(libraries re containers dune-site)
|
||||||
(preprocess (pps ppx_regexp)))
|
(preprocess (pps ppx_regexp ppx_deriving.show)))
|
||||||
|
|
||||||
(env
|
(env
|
||||||
(dev
|
(dev
|
||||||
|
|||||||
+21
@@ -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
|
||||||
|
;;
|
||||||
@@ -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
|
||||||
Reference in new issue
Block a user