Skip to content

Instantly share code, notes, and snippets.

@iamd3vil
Created December 9, 2015 14:25
Show Gist options
  • Save iamd3vil/9a8228a81cf78f5bf6d5 to your computer and use it in GitHub Desktop.
Save iamd3vil/9a8228a81cf78f5bf6d5 to your computer and use it in GitHub Desktop.
Advent of code day 1 solution in Elixir
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