Skip to content

Instantly share code, notes, and snippets.

@adolfont
Last active December 3, 2018 14:53
Show Gist options
  • Select an option

  • Save adolfont/da5e2c8ad5b0aefdc9ff0b34ae280262 to your computer and use it in GitHub Desktop.

Select an option

Save adolfont/da5e2c8ad5b0aefdc9ff0b34ae280262 to your computer and use it in GitHub Desktop.
defmodule Advent1 do
defp process(value, []), do: value
defp process(value, [head | tail]) do
process(value + String.to_integer(head), tail)
end
def do_it(filename) do
{:ok, file} = File.read(filename)
process(0, String.split(file, "\n"))
end
end
IO.puts(Advent1.do_it("input"))
defmodule Advent1 do
defp process(value, already, [], original) do
process(value, already, original, original)
end
defp process(value, already, [head | tail], original) do
if value in already do
value
else
process(value + String.to_integer(head), [value | already], tail, original)
end
end
def do_it(filename) do
{:ok, file} = File.read(filename)
list = String.split(file, "\n")
process(0, [], list, list)
end
end
IO.puts(Advent1.do_it("input"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment