# [Perl 5], 96 + 1 (-p) = 97 bytes

<!-- language-all: lang-perl -->

    @a=0..3*$_;@a[$d,$s]=@a[$s=$a[$_]+$a[$_-1],$d=abs$a[$_]-$a[$_-1]],push@r,$a[1]for 1..$_;$_=pop@r

[Try it online!][TIO-j62ok95w]

[Perl 5]: https://www.perl.org/
[TIO-j62ok95w]: https://tio.run/##K0gtyjH9/98h0dZAT89YSyXe2iExWiVFR6U41hbEKrZVAZLxsdpgStcwVkclxTYxqRgiqgsTjdUpKC3OcCjSAQoYxqblFykY6ukBDVOJty3IL3Ao@v/f9F9@QUlmfl7xf90CAA "Perl 5 – Try It Online"