@@ -5,13 +5,6 @@ defmodule Day17 do
5
5
|> Enum . map ( fn line -> String . graphemes ( line ) |> Enum . map ( & String . to_integer / 1 ) end )
6
6
end
7
7
8
- def get_heat ( { x , y } , heatmap ) do
9
- case heatmap |> Enum . at ( x ) do
10
- nil -> nil
11
- line -> Enum . at ( line , y )
12
- end
13
- end
14
-
15
8
def apply_dir_to_pos ( { x , y } , { dx , dy } ) , do: { x + dx , y + dy }
16
9
@ dirs [ { 1 , 0 } , { 0 , - 1 } , { - 1 , 0 } , { 0 , 1 } ]
17
10
@@ -24,7 +17,7 @@ defmodule Day17 do
24
17
def next_states ( heatmap , grid_lims , costs , min_dist , max_dist , [
25
18
{ { pos , dir , dist } , current_cost } | rest
26
19
] ) do
27
- new_current_cost = get_heat ( pos , heatmap ) + current_cost
20
+ new_current_cost = ( heatmap |> elem ( elem ( pos , 0 ) ) |> elem ( elem ( pos , 1 ) ) ) + current_cost
28
21
29
22
if ! ( costs |> Map . get ( { pos , dir , dist } ) <= new_current_cost ) do
30
23
new_costs = Map . put ( costs , { pos , dir , dist } , new_current_cost )
@@ -68,7 +61,7 @@ defmodule Day17 do
68
61
def next_states ( heatmap , min_dist , max_dist ) ,
69
62
do:
70
63
next_states (
71
- heatmap ,
64
+ heatmap |> Enum . map ( & List . to_tuple / 1 ) |> List . to_tuple ( ) ,
72
65
{ length ( heatmap ) , length ( Enum . at ( heatmap , 0 ) ) } ,
73
66
% { } ,
74
67
min_dist ,
0 commit comments