I've been working through the book and I was surprised to see there wasn't a Scala Solution here. I created a mutable version as close to the original as possible and immutable recursive version.