Skip to content

Commit

Permalink
Type alias
Browse files Browse the repository at this point in the history
  • Loading branch information
drewolson committed Dec 16, 2024
1 parent ba1f73f commit 2c3a402
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/aoc/year2024/day15.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import gleam/list
import gleam/result
import gleam/string

type Expander =
fn(String) -> List(String)

type Coord =
#(Int, Int)

Expand All @@ -17,7 +20,7 @@ type Dir {
Right
}

fn make_grid(str: String, f: fn(String) -> List(String)) -> Grid {
fn make_grid(str: String, f: Expander) -> Grid {
str
|> str.lines
|> list.index_map(fn(l, y) {
Expand All @@ -30,7 +33,7 @@ fn make_grid(str: String, f: fn(String) -> List(String)) -> Grid {
|> dict.from_list
}

fn parse(input: String, f: fn(String) -> List(String)) -> #(Grid, List(Dir)) {
fn parse(input: String, f: Expander) -> #(Grid, List(Dir)) {
let assert Ok(#(a, b)) = string.split_once(input, "\n\n")
let dirs =
b
Expand Down Expand Up @@ -104,7 +107,7 @@ fn expand(c: String) -> List(String) {
}
}

pub fn solve(input: String, block: String, f: fn(String) -> List(String)) -> Int {
pub fn solve(input: String, block: String, f: Expander) -> Int {
let #(grid, dirs) = parse(input, f)
let robot = find_robot(grid)
let #(grid, _) =
Expand Down

0 comments on commit 2c3a402

Please sign in to comment.