What Elixir related stuff are you doing?

A zypper is a wrapper to another datastructure that is able to walk that datastructure back and forth a “cell” in constant time.

Usually they are implemented around three values:

  • the value of the current cell
  • a history, which contains all information necessary to reconstruct the previous structure on a step “backwards”
  • the future which holds more or less the remainder of the original datastructure.

For a list, this could work as following:

iex(1)> [1, 2, 3] |> to_zypper |> forward
%Zypper{value: 2, history: [1], future: [3]}

iex(2)> [1, 2, 3] |> to_zypper |> forward |> forward
%Zypper{value: 3, history: [2, 1], future: []}

iex(3) (v(2) |> backward) == v(1)
true # at least it should ;) this session is virtual and never really had happened

AFAIR exercism asks for a Zypper around a binary tree, so forward is replaced by some left and right, also my backward is called up over there.

But I do hope, that this explanation as well as the contents of the hints-folder can help you make progress. If not say a word and I will split the thread up.

2 Likes