Created
December 2, 2021 12:16
-
-
Save seanmor5/c34f4f2826ef5ffde0adb0f662a172c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Part 1 | |
File.read!('aoc/1.txt') | |
|> String.replace("\r", "") # i am on windows right now :( | |
|> String.split("\n") | |
|> Enum.map(&String.to_integer/1) | |
|> Nx.tensor() | |
|> then(fn x -> | |
Nx.greater(Nx.slice_axis(x, 1, Nx.size(x) - 1, 0), Nx.slice_axis(x, 0, Nx.size(x) - 1, 0)) | |
end) | |
|> Nx.sum() | |
# Part 2 | |
File.read!('aoc/1.txt') | |
|> String.replace("\r", "") # i am on windows right now :( | |
|> String.split("\n") | |
|> Enum.map(&String.to_integer/1) | |
|> Nx.tensor() | |
|> Nx.window_sum({3}, strides: [1]) | |
|> then(fn x -> | |
Nx.greater(Nx.slice_axis(x, 1, Nx.size(x) - 1, 0), Nx.slice_axis(x, 0, Nx.size(x) - 1, 0)) | |
end) | |
|> Nx.sum() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment