Let's Get Clever #1: Fibonacci Sequence
Tags: challenge, fun, coding, programming
Published: 2019-08-13 22:25:30

---
title: Let's Get Clever #1: Fibonacci Sequence
published: true
description: Calculate the Nth digit of the Fibonacci sequence...cleverly!
tags: challenge, fun, coding, programming
series: Let's Get Clever
cover_image: https://thepracticaldev.s3.amazonaws.com/i/v01i5lrkvio0vjb0fwqr.jpeg
---

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...
```

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

Your code should be able to find the `n`th 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](http://www.catb.org/jargon/html/story-of-mel.html) 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.