Skip to content

Instantly share code, notes, and snippets.

@memoriesadrift
Last active October 4, 2022 09:28
Show Gist options
  • Save memoriesadrift/34de2248efe9016ab19bb38de54e6704 to your computer and use it in GitHub Desktop.
Save memoriesadrift/34de2248efe9016ab19bb38de54e6704 to your computer and use it in GitHub Desktop.
["+3", "+3", "+4", "-2", "-4"] # example input
|> Enum.map(&String.to_integer/1)
|> Stream.cycle()
|> Stream.scan(&(&1 + &2))
|> Enum.reduce_while(MapSet.new([0]), fn x, acc ->
if MapSet.member?(acc, x), do: {:halt, x}, else: {:cont, MapSet.put(acc, x)}
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment