-
-
Save orestis/a33c802404c03882fb7cd9b4fe13418d to your computer and use it in GitHub Desktop.
This file contains 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 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