Showing posts from April, 2020

Recursive Fibonacci Rabbits with Python

Let's say we have some magical rabbits. These rabbits never die. A pair of rabbits has 3 more pairs of rabbits in every litter, and they start producing litters after one generation. If you start with one pair of rabbits, how many rabbits will you have in 5 generations? This was the premise of a problem I was working on this week in Python (check out the full problem here: ). I had to draw it out on my white board to wrap my head around it: The idea behind this problem is that finding the number of rabbits in a given generation is similar to calculating a given number in the Fibonacci sequence and that it can be solved recursively, so that's how I did it. Recursive rabbit solution: It doesn't really have to be done recursively, though. I was talking through it with Steven, and we realized that the manual approach I had used on the whiteboard was also fairly efficient. Turns out it can be implemented in fewer lines of cod

Two Versions of Quicksort with Python

I've been taking the Data Structures & Algorithms in Python class on Lately, I've been working on implementing an in-place Quicksort two different ways.  The first way follows the way they explained it in the class video . This version involves moving the pivot after each comparison: The second way is based on a visualization they linked to from the lecture and this tutorial . It moves the pivot after all comparisons for each partition have been made, eliminates the need for the "j" variable that I have in the first version, and is a few lines shorter than the first version, but it is harder for me understand intrinsically:

Drawing with Python turtles library

-Music made in FL Studio -Screen recording with OBS -Code on GitHub (I include a button because I needed to be able to start recording my screen before the animations started):