Let's Get Clever #1: Fibonacci Sequence

codemouse92

Jason C. McDonald

Posted on August 13, 2019

Let's Get Clever #1: Fibonacci Sequence

We spend a lot of time trying to write good code. I don't know about you, but I get weary of hearing the (apt) admonishment "don't be clever".

Everyone needs a break. So, in celebration of all our diverse skills and knowledge, Let's Get Clever!

Challenge #1

Calculate the Nth digit of the Fibonacci sequence.

In the Fibonacci sequence, every element is the sum of the previous two terms.

0, 1, 1, 2, 3, 5, 8...
Enter fullscreen mode Exit fullscreen mode

So, the next value is 5 + 8, or 13.

Your code should be able to find the nth element.

Constraints

  • No hard coding allowed! You may not write out the sequence manually anywhere in your code. Every element (except the initial 0, 1, 1) must be generated by the code.

  • n=0 is 0; n=1 and n=2 are both 1

  • Assume 0 <= n < (2^16 − 1). In other words, don't worry about negative numbers, and assume n is less than the maximum possible value of a 8-bit integer. (Yes, it USED to be a 64-bit integer...I updated the spec to be sane.)

Bonus Points

These are NOT required, but if you achieve any of these goals, major bragging rights!

  • 🔂 No Loops: Can you avoid use of any explicit loops or recursion?

  • ⏱️ Efficiency: Can you beat O(n)?

The Rules

(These will be the same for every Let's Be Clever challenge.)

  1. Your clever code should accomplish the stated goal in whatever way you like. Watch out for edge cases, though.

  2. You may use any language you like. However, I discourage use of deliberately esoteric languages. Cleverness is usually more fun in production languages.

  3. You know all those rules about readability and maintainability? Fuhgeddaboudit. Cleverness is the goal.

  4. Portability, memory safety, security? Bah humbug. Mel is welcome.

  5. Efficiency is not the main goal, but if your cleverness happens to have an efficiency worth bragging about, definitely point it out!

  6. Explain your Cleverness. Don't wait for others to ask you, although you should be prepared to answer questions. The neat side-effect of Clever code is that everyone can learn cool, weird things.

  7. Be open to feedback. Others might be able to spot edge-cases you missed, or have ideas on how to make your Clever approach even more clever.

  8. Preening is permitted, but don't be obnoxious about it, and be equally liberal with your complements of others. Leave false modesty in the drawer. (Imposter Syndrome sucks, so let's use this to give it a good kick in the teeth.)

  9. Upvote Cleverness! If you really like someone's solution, be sure to give it a Like.

  10. Always be polite and constructive. Please don't criticize anyone for not being clever enough, not understanding what you did, or asking a "stupid question". This is Cleverness on display. Be the tour guide!

Don't forget: CODE HACKERY ENCOURAGED! No holds barred.

💖 💪 🙅 🚩
codemouse92
Jason C. McDonald

Posted on August 13, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Let's Get Clever #2: Spades
challenge Let's Get Clever #2: Spades

August 20, 2019

Let's Get Clever #1: Fibonacci Sequence
challenge Let's Get Clever #1: Fibonacci Sequence

August 13, 2019