Skip to content

Instantly share code, notes, and snippets.

@ignaciovazquez
Created December 4, 2015 13:53
Show Gist options
  • Save ignaciovazquez/b0eb864a3c5e8e869940 to your computer and use it in GitHub Desktop.
Save ignaciovazquez/b0eb864a3c5e8e869940 to your computer and use it in GitHub Desktop.
Advent of Code. Day 4.
# Part 1
integer_stream = Stream.iterate(1, &(&1 + 1))
result = Enum.find(integer_stream, fn n ->
case :crypto.hash(:md5, "bgvyzdsv" <> to_string(n)) |> Base.encode16 |> to_char_list do
[48, 48, 48, 48, 48 | _ ] -> n
_ -> false
end
end)
IO.puts result
# Part 2
integer_stream = Stream.iterate(result, &(&1 + 1))
result = Enum.find(integer_stream, fn n ->
case :crypto.hash(:md5, "bgvyzdsv" <> to_string(n)) |> Base.encode16 |> to_char_list do
[48, 48, 48, 48, 48, 48 | _ ] -> n
_ -> false
end
end)
IO.puts result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment