I got this problem from a co-worker and I think it does a good job of seeing if a programmer can think outside the box.
- You have 16 bits available for data storage between calls.
- Compose a function, and find a way to know when the function has been called approximately one million times.
- You MAY NOT use any additional memory space other than the 16 bits given.
- Recursion may be used for efficiency, but, again, you MAY NOT use memory definition inside the recursion frames: only the 16 bits.
Figured it out? Post the answer in a comment. Haven't figured it out? Don't read the comments until you do!
It took me about 3 minutes of working through approaches that wouldn't work until I got that a-ha moment.