Category: Code

The Fibonacci Sequence

Of late, I’ve been trying to get to the base of how algorithms and mathematics works in general. I’ve wanted to do this for a while because I have an inane fear of Mathematics, and I wanted to face it.

This was also an effort to deep dive into the fundamentals of Computer Science, a topic dear to my heart, but something I’ve ignored for a while. I chanced upon Teach Yourself CS, a good roadmap for getting started with brushing up your CS fundamentals.

As a part of this roadmap, I’ve been solving programs on Project Euler, Hacker Rank and other competitive coding websites. And almost all programs will have a challenge that includes the Fibonacci Sequence.

For ex : Here is Project Euler’s 2nd Program

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89,

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

and here’s how I solved it

i = 0
j = 1
sum = 0
num = 0
while (num < 4000000):    
     num = i + j    
     i = j    
     j = num    
     if num % 2 == 0:        
     sum = sum + num    
print("Final Sum is")

If you can overlook my use of the while loop and my amateur Python skills, this looks like a good start. However while working on this program, I went on a rabbit hole, trying to read more about Fibonacci Sequence.

That’s when I stumbled upon the different applications for the sequence. One fun use case is Planning Poker, where participants in a Scrum meeting are given the sequence cards for estimation.

But what enchanted me was the fact that the sequence appears in biological settings as well. For ex: Some flowers are pentagonal because of the arrangement of spirals.

And it also extends into genealogy as well. Bees for that matter.

  • If an egg is laid by an unmated female, it hatches a male or drone bee.
  • If, however, an egg was fertilized by a male, it hatches a female.

And thus, if one were to trace the ancestory of any male bee, he has 1 parent bee, 2 grandparents, 3 great grand parents and so on.

While learning all these facts about how mathematics and nature are interlocked, I was reminded of Rene Descartes quote

In my opinion, everything happens in nature in a mathematical way.


When CURL fails

Every once in a while, as a programmer, you seemingly come upon a problem that flummoxes you, irritates you and takes you through a wide array of emotions – and in the end when you solve it, makes you look back and think, why did this issue even take so much time to fix.



In one of the recent projects that I have been working on, I had to look for a word in a phrase – but the challenge was to rank an occurrence of the phrase higher when it’s an individual word as compared to when it was part of a word.


Deploying with Deploybot

I vividly remember the first time, I messed up a production server. It was my early days of being a programmer, and we had got our first client.

Back then, my deployment strategy was basically to upload files using FTP and then run any commands on the server via the shell. During a routine deployment, I noticed a file which remained in the server, and in trying to remove it, I typed sudo rm -rf /.

On the Production.


Autosaving in XCode

While working on a Swift Project, I spent ~ 3-5 hours adjusting a few pop-ups and fine tuning design for a screen. As it so happens, while working in the zone, I missed any committing and committed the code after my entire sprint.