Skip to content

Instantly share code, notes, and snippets.

@asimpson
Last active Dec 2, 2021
Embed
What would you like to do?
readings =
File.read!("day-1-input.txt")
|> String.split("\n", trim: true)
|> Enum.map(&String.to_integer/1)
count =
Enum.with_index(readings)
|> Enum.count(fn {x, i} ->
prev = if i > 0, do: i - 1, else: 0
x > Enum.at(readings, prev)
end)
IO.inspect(count, label: "count is")
chunks =
File.read!("day-1-input.txt")
|> String.split("\n", trim: true)
|> Enum.map(&String.to_integer/1)
|> Enum.chunk_every(3, 1)
chunk_size = length(chunks)
count =
Enum.with_index(chunks)
|> Enum.count(fn {x, i} ->
next = Enum.at(chunks, i + 1)
if i < chunk_size - 1 && length(next) == 3 do
c = Enum.sum(x)
n = Enum.sum(next)
n > c
end
end)
IO.inspect(count, label: "count is")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment