Skip to content

Commit

Permalink
simplify grid
Browse files Browse the repository at this point in the history
  • Loading branch information
Janiczek committed Dec 16, 2024
1 parent f15735c commit 85afdc8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/aoc_2024/day_16.gleam
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import gleam/bool
import gleam/dict.{type Dict}
import gleam/int
import gleam/io
import gleam/list
import gleam/option.{None, Some}
import gleam/order
Expand Down Expand Up @@ -150,12 +149,12 @@ pub fn pt_2(input: Input) {
best: 109_496,
)
//io.println_error(
// grid.to_string(input.grid, fn(xy, c) {
// grid.to_string_simple(input.grid, fn(xy, c) {
// case set.contains(steps, xy), c {
// True, Error(Nil) -> #("O", Error(Nil))
// True, Error(Nil) -> "O"
// True, Ok(Nil) -> panic as "walked over a wall?"
// False, Error(Nil) -> #(".", Error(Nil))
// False, Ok(Nil) -> #("#", Error(Nil))
// False, Error(Nil) -> "."
// False, Ok(Nil) -> "#"
// }
// }),
//)
Expand Down
14 changes: 14 additions & 0 deletions src/grid.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,20 @@ pub fn to_string(
|> string.join("\n")
}

pub fn to_string_simple(
grid grid: Grid(a),
fun fun: fn(XY, Result(a, Nil)) -> String,
) -> String {
let x_range = list.range(from: grid.dims.min_x, to: grid.dims.max_x)
list.range(from: grid.dims.min_y, to: grid.dims.max_y)
|> list.map(fn(y) {
x_range
|> list.map(fn(x) { fun(#(x, y), get(grid, #(x, y))) })
|> string.concat
})
|> string.join("\n")
}

pub fn find_all_exact(grid: Grid(a), a: a) -> List(XY) {
grid.data
|> dict.to_list()
Expand Down

0 comments on commit 85afdc8

Please sign in to comment.