AdventOfCode/2020/elixir/day3/day3part1.exs

23 lines
503 B
Elixir
Raw Normal View History

2020-12-03 05:37:29 +00:00
defmodule Day3Part1 do
def run do
{x, y, trees} =
File.read!("input")
|> String.trim()
|> String.split("\n")
|> Enum.map(&String.to_charlist/1)
|> Enum.reduce({0, 0, 0}, fn row, {x, y, trees} ->
trees =
case Stream.cycle(row) |> Enum.at(x) do
?# -> trees + 1
?. -> trees
end
{x + 3, y + 1, trees}
end)
IO.puts("Travelled (#{x}, #{y}) and encountereed #{trees} trees")
end
end
Day3Part1.run()