Last active
October 4, 2022 09:28
-
-
Save memoriesadrift/34de2248efe9016ab19bb38de54e6704 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
["+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