Day 2024 part 1
This commit is contained in:
@@ -66,14 +66,15 @@ module Grid = struct
|
||||
|
||||
let idx_from_opt grid = String.index_from_opt grid.grid
|
||||
|
||||
let update_pos grid pos c =
|
||||
let idx = idx_of_pos grid pos in
|
||||
let update_idx grid idx c =
|
||||
let builder = Buffer.create (length grid) in
|
||||
Buffer.add_string builder (String.sub grid.grid 0 idx);
|
||||
Buffer.add_char builder c;
|
||||
Buffer.add_string builder
|
||||
(String.sub grid.grid (idx + 1) (length grid - idx - 1));
|
||||
{ grid with grid = Buffer.contents builder }
|
||||
|
||||
let update_pos grid pos c = update_idx grid (idx_of_pos grid pos) c
|
||||
end
|
||||
|
||||
let log10i i =
|
||||
|
@@ -143,4 +143,8 @@ module Grid : sig
|
||||
val update_pos : t -> int * int -> char -> t
|
||||
(** [Grid.update_pos grid pos c] returns a grid with the character at position
|
||||
[pos] changed to [c]. *)
|
||||
|
||||
val update_idx : t -> int -> char -> t
|
||||
(** [Grid.update_pos grid idx c] returns a grid with the character at index
|
||||
[idx] changed to [c]. *)
|
||||
end
|
||||
|
Reference in New Issue
Block a user