Introduction
Our recent blog post on Operator Precedence Riddles in Ruby discussed how logic can subtley run awry without a solid grasp of operator precedence.
Following up on this I thought it might be good to create a short quiz to allow readers to test themselves on this topic. Have a go at the short quiz below to see how well you know your operator precedence rules in ruby!
I have added a timer to make it a bit more interesting. The timer is set for 30 seconds per question, except for question 10 where I have given you 1 minute. You should be all done in just over 6 minutes. If you struggle with any of the questions you will get a chance to review the correct answers at the end, so stick around for that.
Let us know how you got on in the comments. Good luck!
References
- Original blog post on operator precedence riddles in ruby.
- Ruby docs for operator precedence
- GitHub gist with single script evaluating the 12 examples in this quiz
Comments
Really, bitwise calculation mentally? You should use smaller values for that question, the focus is the precedence, not the bitwise calculation.
xTSRVrqQJ
OK fair point. This was the reason I had increased the time limit to 1 minute for that particular question, but I guess that is still going to be challenging, especially if you are trying to do it in your head. Personally, I reach for a pen and paper when doing any sort of binary arithmetic. Sorry hadn't really considered that rough working wasn't going to be an option for some readers :-(
Got your own view or feedback? Share it with us below …