It happens to the best of us, you’re faced with a seemingly simple problem and you can’t figure it out to save your life. On the surface it’s easy but you start to get wrapped up in hypothetical situations and premature optimization to the point that you’re completely incapacitated.
It happened to me not too long ago, at the worst opportune time, during a job interview. You see, as it turns out, I’ve never had to write code to figure out if a number exists in Fibonacci sequence until recently. When asked about this I got all up in my own head and couldn’t solve the issue. I got in my own way.
You see, I started to over think the problem. I was convinced there was some smart kid way to determine if a number was in the sequence without knowing any of the previous numbers in the sequence. I missed the obvious fact that you could simply walk through the sequence and see if the number in question exists in there and returning false when the sequence exceeds the passed number.
I knew that solution existed, but it just didn’t seem right to me at the time. The fact is, I was too busy trying to be clever and trying to find a smart kid solution that may or may not even exist. Because I was convinced that this solution existed I exhausted my time allotment trying to get there.
After the fact I was able to sit down and knock out the code in only a few minutes, and it worked fine because even though the sequence itself is infinite, the values in the sequence get so large so fast it remains quite manageable. Couple that with only storing the last 2 numbers in the sequence instead of the entire thing, boom this shouldn’t have been so hard for me.
The situation was humbling as hell but also gave me a new perspective on how to approach problems. I was reminded that I need to keep shit simple as can be and optimize when you need to, not because you think you’re supposed to. The last few weeks have been some of the most productive I’ve had in a while because of this. Simple solutions may not be able to scale but being productive and getting shit done never goes out of style.