Skip to content

Instantly share code, notes, and snippets.

@orestis
Created December 25, 2016 12:05
Show Gist options
  • Save orestis/a33c802404c03882fb7cd9b4fe13418d to your computer and use it in GitHub Desktop.
Save orestis/a33c802404c03882fb7cd9b4fe13418d to your computer and use it in GitHub Desktop.
defmodule Day25 do
def actual_program(d, io) do
a = d
a = div(a, 2)
c = rem(a, 2)
io = [c|io]
if a == 0 do
io
else
actual_program(a, io)
end
end
def check(io) when rem(length(io), 2) == 0 do
Enum.all?(Enum.chunk(io, 2), fn(p) -> p == [0, 1] end)
end
def check(_), do: false
def solve() do
Stream.iterate(0, &(&1 + 1))
|> Stream.drop_while(fn(a) ->
d = a + 14 * 182
not check(actual_program(d, []))
end)
|> Enum.take(1)
|> Enum.at(0)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment