Day 2024 part 1

This commit is contained in:
2024-12-20 09:34:32 +00:00
parent defeaa6db3
commit 1f8a8a8e53
4 changed files with 98 additions and 4 deletions

View File

@@ -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 =

View File

@@ -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