Your task is to implement the shortest and cleanest form of a stack in Lua. To have your code pass this challenge, you need to have a "push" method of the stack object, which accepts a value and adds it to the top of the stack, and a "pop" method of the stack object, which removes and returns the top value of the stack. Lastly, all stack objects should be different, meaning stack1==stack2 will ALWAYS be false, assuming stack1 and stack2 are different.
I already have a solution in mind, but I want to see how you guys think (and if you can get it shorter than me ).
"your actions cause me to infer your ego is the size of three houses" -finley
The specifications are "create an object", meaning you can use :push and :pop to modify the stack. s={} doesn't give the "push" and "pop" methods, and the above doesn't quite create an object, although it's certainly interesting.
"your actions cause me to infer your ego is the size of three houses" -finley
Why mandate explicit object methods for the API? That seems unnecessarily restrictive and a design choice rather than a requirement for a real stack implementation.
Liking the Illuminati icon, slime!
I do think the object API is a bit unnecessary, but I guess it makes it more challenging. For the point of the challenge: do spaces and newlines / tabs count as "characters"?
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
davisdude wrote:Liking the Illuminati icon, slime!
I do think the object API is a bit unnecessary, but I guess it makes it more challenging. For the point of the challenge: do spaces and newlines / tabs count as "characters"?
Yes. Also, the point of forcing the methods was to make it a challenge. As kikito said, "a={}" is technically a stack, so that'd rather ruin the challenge. It's not an obvious method I used to get it as short as I did, although it's obvious in retrospect.
"your actions cause me to infer your ego is the size of three houses" -finley