Created
December 9, 2015 14:25
-
-
Save iamd3vil/9a8228a81cf78f5bf6d5 to your computer and use it in GitHub Desktop.
Advent of code day 1 solution in Elixir
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 | |
def part1("(" <> rest, count) do | |
part1(rest, count + 1) | |
end | |
def part1(")"<> rest, count) do | |
part1(rest, count - 1) | |
end | |
def part1("", count), do: count | |
def part2(_, -1, pos), do: pos - 1 | |
def part2("(" <> rest, count, pos) do | |
part2(rest, count + 1, pos + 1) | |
end | |
def part2(")" <> rest, count, pos) do | |
part2(rest, count - 1, pos + 1) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment