tangled
alpha
login
or
join now
hauleth.dev
/
advent-of-code
3
fork
atom
this repo has no description
3
fork
atom
overview
issues
pulls
pipelines
chore: add tasks headers
hauleth.dev
4 years ago
0895610e
7889fd6e
+28
-6
1 changed file
expand all
collapse all
unified
split
2021
solutions.livemd
+28
-6
2021/solutions.livemd
···
838
{:module, Day10, <<70, 79, 82, 49, 0, 0, 7, ...>>, {:parse, 2}}
839
```
840
0
0
841
```elixir
842
points = %{
843
?) => 3,
···
858
```output
859
288291
860
```
0
0
861
862
```elixir
863
points = %{
···
919
920
@diffs for dx <- -1..1, dy <- -1..1, dx != 0 or dy != 0, do: {dx, dy}
921
922
-
IO.inspect(@diffs)
923
-
924
def lightup(map, n) do
925
map
926
|> Enum.reduce({map, 0}, fn
···
951
```
952
953
```output
954
-
[{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}]
955
```
956
957
-
```output
958
-
{:module, Day11, <<70, 79, 82, 49, 0, 0, 11, ...>>, {:lightup, 2}}
959
-
```
960
961
```elixir
962
draw = fn map ->
···
978
```output
979
1688
980
```
0
0
981
982
```elixir
983
Stream.unfold(1, &{&1, &1 + 1})
···
1052
{:module, Day12, <<70, 79, 82, 49, 0, 0, 15, ...>>, {:small?, 1}}
1053
```
1054
0
0
1055
```elixir
1056
Day12.dfs(graph, "start", "end")
1057
```
···
1059
```output
1060
4167
1061
```
0
0
1062
1063
```elixir
1064
Day12.dfs2(graph, "start", "end")
···
1131
{:module, Day13, <<70, 79, 82, 49, 0, 0, 13, ...>>, {:draw, 1}}
1132
```
1133
0
0
1134
```elixir
1135
Day13.fold(hd(folds), input) |> MapSet.size()
1136
```
···
1138
```output
1139
802
1140
```
0
0
1141
1142
```elixir
1143
Enum.reduce(folds, input, &Day13.fold/2)
···
1219
{:module, Day14, <<70, 79, 82, 49, 0, 0, 13, ...>>, {:frequencies, 1}}
1220
```
1221
0
0
1222
```elixir
1223
{{_, min}, {_, max}} =
1224
1..10
···
1235
```output
1236
2768
1237
```
0
0
1238
1239
```elixir
1240
{{_, min}, {_, max}} =
···
1275
{99, 99}
1276
```
1277
0
0
1278
```elixir
1279
shortest_paths =
1280
for y <- height..0//-1,
···
1299
```output
1300
429
1301
```
0
0
1302
1303
```elixir
1304
defmodule Day15.Task2 do
···
1913
}
1914
```
1915
0
0
1916
```elixir
1917
defmodule Day16.Task1 do
1918
alias Day16.Packet
···
1930
```output
1931
949
1932
```
0
0
1933
1934
```elixir
1935
defmodule Day16.Task2 do
···
838
{:module, Day10, <<70, 79, 82, 49, 0, 0, 7, ...>>, {:parse, 2}}
839
```
840
841
+
### Task 1
842
+
843
```elixir
844
points = %{
845
?) => 3,
···
860
```output
861
288291
862
```
863
+
864
+
### Task 2
865
866
```elixir
867
points = %{
···
923
924
@diffs for dx <- -1..1, dy <- -1..1, dx != 0 or dy != 0, do: {dx, dy}
925
0
0
926
def lightup(map, n) do
927
map
928
|> Enum.reduce({map, 0}, fn
···
953
```
954
955
```output
956
+
{:module, Day11, <<70, 79, 82, 49, 0, 0, 11, ...>>, {:lightup, 2}}
957
```
958
959
+
### Task 1
0
0
960
961
```elixir
962
draw = fn map ->
···
978
```output
979
1688
980
```
981
+
982
+
### Task 2
983
984
```elixir
985
Stream.unfold(1, &{&1, &1 + 1})
···
1054
{:module, Day12, <<70, 79, 82, 49, 0, 0, 15, ...>>, {:small?, 1}}
1055
```
1056
1057
+
### Task 1
1058
+
1059
```elixir
1060
Day12.dfs(graph, "start", "end")
1061
```
···
1063
```output
1064
4167
1065
```
1066
+
1067
+
### Task 2
1068
1069
```elixir
1070
Day12.dfs2(graph, "start", "end")
···
1137
{:module, Day13, <<70, 79, 82, 49, 0, 0, 13, ...>>, {:draw, 1}}
1138
```
1139
1140
+
### Task 1
1141
+
1142
```elixir
1143
Day13.fold(hd(folds), input) |> MapSet.size()
1144
```
···
1146
```output
1147
802
1148
```
1149
+
1150
+
### Task 2
1151
1152
```elixir
1153
Enum.reduce(folds, input, &Day13.fold/2)
···
1229
{:module, Day14, <<70, 79, 82, 49, 0, 0, 13, ...>>, {:frequencies, 1}}
1230
```
1231
1232
+
### Task 1
1233
+
1234
```elixir
1235
{{_, min}, {_, max}} =
1236
1..10
···
1247
```output
1248
2768
1249
```
1250
+
1251
+
### Task 2
1252
1253
```elixir
1254
{{_, min}, {_, max}} =
···
1289
{99, 99}
1290
```
1291
1292
+
### Task 1
1293
+
1294
```elixir
1295
shortest_paths =
1296
for y <- height..0//-1,
···
1315
```output
1316
429
1317
```
1318
+
1319
+
### Task 2
1320
1321
```elixir
1322
defmodule Day15.Task2 do
···
1931
}
1932
```
1933
1934
+
### Task 1
1935
+
1936
```elixir
1937
defmodule Day16.Task1 do
1938
alias Day16.Packet
···
1950
```output
1951
949
1952
```
1953
+
1954
+
### Task 2
1955
1956
```elixir
1957
defmodule Day16.Task2 do