Skip to content

Instantly share code, notes, and snippets.

@seanmor5
Created December 2, 2021 12:16
Show Gist options
  • Save seanmor5/c34f4f2826ef5ffde0adb0f662a172c2 to your computer and use it in GitHub Desktop.
Save seanmor5/c34f4f2826ef5ffde0adb0f662a172c2 to your computer and use it in GitHub Desktop.
# 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