Skip to content

Instantly share code, notes, and snippets.

View memoriesadrift's full-sized avatar

Sam S memoriesadrift

View GitHub Profile
["+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)