DEV Community

Discussion on: Challenge - Print Spiral

Collapse
 
stangls profile image
Stefan Dangl

It does not have to be a purely math problem on Level 2.

I implemented this recursive approach which prepends and appends to lines of smaller spirals.

Of course you may ask, if using the call-stack isn't similar to a data structure, and from a theoretical point of view (Touring machine) it is. So here is a version without recursion using tailrec.

And then there is also the solution of not using any intermediate data structure at all and printing directly

Sorry for not having enough time to write really nice code.

Collapse
 
heikodudzus profile image
Heiko Dudzus • Edited

Recursion was the way to go for me, too, because of the recursive structure of spirals. Really nice to see your recursive solutions! :)

I shared your view about how collecting data on the call stack is analogous to building a data structure regarding space complexity, and came to your conclusion to use tail recursion.