These are obviously generic enough and useful for the future that they can be moved to a shared library.
77 lines
2.7 KiB
OCaml
77 lines
2.7 KiB
OCaml
val ints_of_string : ?sep:string -> string -> int list
|
|
(** [nums_from_string ?sep s] takes a string of integers separated by [sep] and
|
|
gives back a list of the integers. By default [sep] is " " *)
|
|
|
|
val distance1 : int -> int -> int
|
|
(** [distance1 a b] returns the absolute difference between [a] and [b]. *)
|
|
|
|
val strings_of_file : string -> string list
|
|
(** [strings_from_file fname] returns a list of strings from the file [fname].
|
|
Each string represents a line from the file. *)
|
|
|
|
val main : (string -> 'a) -> (('b -> string) * ('a -> 'b)) list -> unit
|
|
(** [main prep parts] executes an advent of code problem. [prep fname] should be
|
|
a function that returns the input from [fname]. Each elemet of [parts] is a
|
|
pair of functions. The first converts the output to a string (for example
|
|
[string_of_int]). The second executes the given part. Output is given as if
|
|
done by: [print_string ( prep fname |> snd |> fst )] *)
|
|
|
|
(** Module representing a pair of integers, useful for Set.Make *)
|
|
module IntPair : sig
|
|
type t = int * int
|
|
(** [t] is a pair of integers *)
|
|
|
|
val compare : t -> t -> int
|
|
(** Standard comparion operation. *)
|
|
end
|
|
|
|
(** IntPairSet represents a Set of integers, see standard docs for info. *)
|
|
module IntPairSet : sig
|
|
type elt = IntPair.t
|
|
type t = Set.Make(IntPair).t
|
|
|
|
val empty : t
|
|
val add : elt -> t -> t
|
|
val singleton : elt -> t
|
|
val remove : elt -> t -> t
|
|
val union : t -> t -> t
|
|
val inter : t -> t -> t
|
|
val disjoint : t -> t -> bool
|
|
val diff : t -> t -> t
|
|
val cardinal : t -> int
|
|
val elements : t -> elt list
|
|
val min_elt : t -> elt
|
|
val min_elt_opt : t -> elt option
|
|
val max_elt : t -> elt
|
|
val max_elt_opt : t -> elt option
|
|
val choose : t -> elt
|
|
val choose_opt : t -> elt option
|
|
val find : elt -> t -> elt
|
|
val find_opt : elt -> t -> elt option
|
|
val find_first : (elt -> bool) -> t -> elt
|
|
val find_first_opt : (elt -> bool) -> t -> elt option
|
|
val find_last : (elt -> bool) -> t -> elt
|
|
val find_last_opt : (elt -> bool) -> t -> elt option
|
|
val iter : (elt -> unit) -> t -> unit
|
|
val fold : (elt -> 'acc -> 'acc) -> t -> 'acc -> 'acc
|
|
val map : (elt -> elt) -> t -> t
|
|
val filter : (elt -> bool) -> t -> t
|
|
val filter_map : (elt -> elt option) -> t -> t
|
|
val partition : (elt -> bool) -> t -> t * t
|
|
val split : elt -> t -> t * bool * t
|
|
val is_empty : t -> bool
|
|
val mem : elt -> t -> bool
|
|
val equal : t -> t -> bool
|
|
val compare : t -> t -> int
|
|
val subset : t -> t -> bool
|
|
val for_all : (elt -> bool) -> t -> bool
|
|
val exists : (elt -> bool) -> t -> bool
|
|
val to_list : t -> elt list
|
|
val of_list : elt list -> t
|
|
val to_seq_from : elt -> t -> elt Seq.t
|
|
val to_seq : t -> elt Seq.t
|
|
val to_rev_seq : t -> elt Seq.t
|
|
val add_seq : elt Seq.t -> t -> t
|
|
val of_seq : elt Seq.t -> t
|
|
end
|