Wednesday, February 14, 2024

Programming Fun With Fibonacci Numbers






When you are learning about recursive functions in programming, two examples from mathematics are used to teach the concept: calculating factorials and the Fibonacci sequence.

Let's look at Fibonacci.  The sequence starts with 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...

So, the first two values are: fib(0) = 0, fib(1)=1

After that, the next fib number is the sum of the previous two,  So, fib(2) = fib(0) + fib(1), fib(3) = fib(2) + fib(1), etc.

I saw an online discussion of someone wanting to sum the first N Fibonacci sequence, and looking for an efficient recursive program.


I wondered if you even needed recursion for the sum since, when you are summing integers, you can do it without a loop or recursion.  The sum of the first N integers is N(N+1)/2

So, I dug in and found that you can sum the first N Fibonacci numbers without loops or recursion.

1. First, we can define the constant phi =  (1 + sqrt(5))/2   #1 plus the square root of 5, divided by 2

2. Next, we can create a function to calculate the nth Fibonacci number without loops or recursion:
fib(n) =  int_round_up {[ phi ^ n - (-1 / phi) ^ n ] / sqrt(5) }  # do the calc in decimal and round up to int

3.  Finally, the function to find the sum of the first N Fibonacci numbers:
Sum_fib(n) = fib(n+2) - 1  # The sum of the first N Fib numbers is just the N+2 Fib number - 1

So, it turns out finding the sum of Fibonacci numbers is actually a simple, elegant process.


© 2024 Praveen Puri

Thursday, February 8, 2024

We Are Truly Living in a Multicultural World

My wife sent me to a Polish bakery this afternoon the pick up some homemade Paczki, which was only for sale today.  

The Polish bakery was inside a Polish grocery store, that had a small restaurant inside, that was advertising authentic Mexican food, made from 100% halal meat!



© 2024 Praveen Puri

Wednesday, February 7, 2024

Breaking The Democrat-Republican Duopoly.

Many voters aren't happy to only have a choice of Trump vs. Biden.

We will never break the duopoly unless we either get ranked choice voting, or even something simpler such as being able to vote a second choice (so that, if your first choice isn't in the top two, your second choice counts if it's one of the top two). 

That way, people will get comfortable voting third party candidates.

© 2024 Praveen Puri

Three Keys to Technology-Based Innovation


1. Value simplicity. If your solution is not the simplest and easiest to use, it will lose in the marketplace to the one that is.

2. Recognize the power of iteration. It's not "succeed or fail", it's "succeed or iterate". Failure only occurs if you give up.

3. Embrace analog over digital thinking. Digital thinking is all or nothing, while analog thinking recognizes that result is a spectrum, and a partial success is often very valuable.


© 2024 Praveen Puri

Monday, February 5, 2024

Today, Owning A Product Means You're Responsible For The Full Life Cycle

Today's Wall Street Journal had an article about Whirlpool re-designing their fridges to make them easier to recycle.  

Why would they go to all the trouble, when it does not improve the product's functioning?

Because, today, customers are more environmentally conscious and they expect product creators to be responsible for the complete lifecycle of their products.


© 2024 Praveen Puri

Sunday, February 4, 2024

Strategic Simplicity® Takes Work

It takes work to make the hard & complex simple. Ironically, simplicity first requires diving into the noise.

© 2024 Praveen Puri

Strategic Simplicity® in Advertising

Companies need Strategic Simplicity® in advertising because customers are busy, and you need to break through the noise!

© 2024 Praveen Puri