Last active
December 3, 2018 14:53
-
-
Save adolfont/da5e2c8ad5b0aefdc9ff0b34ae280262 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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")) |
This file contains hidden or 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
| 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