Compare commits
2 Commits
7fbad713c3
...
590637e0de
Author | SHA1 | Date | |
---|---|---|---|
590637e0de
|
|||
7b51696740
|
@@ -1 +1 @@
|
||||
version = 0.26.2
|
||||
version = 0.27.0
|
||||
|
@@ -1,7 +1,7 @@
|
||||
(** [pair_nums_from_string s] takes a string of two numbers separated by
|
||||
whitespace and returns the pair of the numbers *)
|
||||
let pair_ints_of_string s =
|
||||
match Aoc.ints_of_string s with
|
||||
match Aoc.ints_of_string ~sep:" " s with
|
||||
| [ h; h' ] -> (h, h')
|
||||
| _ -> raise (Invalid_argument "pair_nums_from_string")
|
||||
|
||||
@@ -16,7 +16,7 @@ let rev_split lst =
|
||||
impl [] [] lst
|
||||
|
||||
(** [count lst n] counts the number of times [n] appears as an element in [lst].
|
||||
*)
|
||||
*)
|
||||
let count lst n =
|
||||
List.fold_left (fun acc x -> if x = n then acc + 1 else acc) 0 lst
|
||||
|
||||
|
@@ -36,8 +36,8 @@ let rec is_page_order_valid m pages =
|
||||
match pages with h :: t -> impl h t && is_page_order_valid m t | [] -> true
|
||||
|
||||
(** [parse_rules lst] parses the rules in the list [lst] stopping when
|
||||
encountering an empty line. Returns a pair [(rule_map, tail)].
|
||||
[tail] starts the line after the empty line. *)
|
||||
encountering an empty line. Returns a pair [(rule_map, tail)]. [tail] starts
|
||||
the line after the empty line. *)
|
||||
let parse_rules =
|
||||
let m = Hashtbl.create 17 in
|
||||
let rec impl = function
|
||||
|
@@ -12,7 +12,8 @@ let main prep parts =
|
||||
| [| _; fname |] ->
|
||||
let lines = prep fname in
|
||||
let do_part i (fmt, fn) =
|
||||
Printf.printf "Part %d = %s\n" (i + 1) (fmt (fn lines))
|
||||
Printf.printf "Part %d = %s\n" (i + 1) (fmt (fn lines));
|
||||
flush stdout
|
||||
in
|
||||
List.iteri do_part parts;
|
||||
exit 0
|
||||
|
15
lib/aoc.mli
15
lib/aoc.mli
@@ -6,13 +6,12 @@ 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. *)
|
||||
(** [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 )] *)
|
||||
(** [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 )] *)
|
||||
|
Reference in New Issue
Block a user