Tidy up code for 2024 day 12.
This still has some mutable state.
This commit is contained in:
@@ -54,12 +54,16 @@ module Grid = struct
|
||||
let length grid = String.length grid.grid
|
||||
let pos_of_idx grid idx = (idx mod grid.width, idx / grid.width)
|
||||
let idx_of_pos grid (x, y) = x + (y * grid.width)
|
||||
let get_by_idx grid idx = grid.grid.[idx]
|
||||
let get_by_pos grid pos = get_by_idx grid (idx_of_pos grid pos)
|
||||
|
||||
let pos_is_valid grid (x, y) =
|
||||
x >= 0 && x < grid.width && y >= 0 && y < grid.height
|
||||
|
||||
let get_by_idx grid idx = grid.grid.[idx]
|
||||
let get_by_pos grid pos = get_by_idx grid (idx_of_pos grid pos)
|
||||
|
||||
let get_by_pos_opt grid pos =
|
||||
if pos_is_valid grid pos then Some (get_by_pos grid pos) else None
|
||||
|
||||
let idx_from_opt grid = String.index_from_opt grid.grid
|
||||
|
||||
let update_pos grid pos c =
|
||||
|
Reference in New Issue
Block a user