-
-
Save asimpson/360847dedecba562dc8323389f2b63ce 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
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") |
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
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