Drake Equation Calculator

I’ve been mentally working on new program for a week or two. What I wanted this program to do is to calculate the Drake Equation based on whatever variable I put in. I could try different values and see how that effects the total number. Sort of like this.

The Drake Equation is an equation that helps us think about how rare or prolific aliens who could communicate with us might be. The results of the Drake Equation aren’t really considered an accurate estimate of the occurrence of intelligent life, because every variable is an estimate. These estimates vary greatly based on a person’s opinion or philosophy, as well as what scientists have learned. While I don’t think anyone should put too much stock in the equation’s results, I find it really interesting how two different people can have such vastly different numbers.

Needing to practice Ruby more, I thought programming a Drake Equation calculator would be a good exercise. It allows me to use different values each time I run the program, plus I can add on more variables if I want to.

For my program, I wrote two methods: one that will allow the user to put in each variable and one that will multiply an array of variables. The program then calls the variable method to get values for each variable. After getting all the variables, they’re fed into an array, which gets fed into a method that multiplies them together. Other that all of the strings (text) that explains what the variables are, it’s a very short program. (The line numbers are so high because of all my notes at the top defining what the Drake Equation variables are :P)

I ended up having to look up a few things to make this program. First, I had to look up the Drake Equation. I needed to know exactly what each variable stands for and how to describe them. I decided to keep the Drake Equation’s original variable names because it seemed an easier way to keep them straight.

I also had to look up how to do a couple things in Ruby. First, I needed to convert a string to a float. I should’ve been able to guess that it would be .to_f, simply because I already knew that to convert an integer to a string I use .to_s. I also had to look up how to multiply all the floats in my “milkyway” array together. I used .inject(:*) to multiply my array values together.

I double checked how my program calculates, and it seems to work just fine. I’ve run it a few times with different values for the variables, getting wildly different answers. I also expanded the program out to include all of the galaxies we know about, not just the Milky Way.

I’m actually pleasantly surprised at how easy it was to make this program. With getting back into programming, the parts I’ve had trouble with are keeping my variables straight and organizing the objects. Really thinking out how I wanted the program to work and how to achieve that in logical steps helped make the programming itself go quick, without hiccups. I think drawing out a mind map would help me work like this in future projects.

This entry was posted in Coding, Programs and tagged , , , , , . Bookmark the permalink.

2 Responses to Drake Equation Calculator

  1. seepurple says:

    It’s very very interesting but I have to say it’s way over my head. I wish I could understand it better because it does sound interesting. Let me know how it goes. (ps for some reason your “like” button does not work on your site at the moment.)

  2. Val says:

    If your interested in programming, I’d suggest Ruby to start with. It’s been a lot easier & faster to learn than C++ was for me. All programming languages look crazy at first, but after practicing you start to see the logic. It’s sorta like the first time you see an sms or tweet with all the crazy abbreviations we use: it makes no sense at first, but after a bit you get the hang of it. The special words, like “puts” for “put string”, are logical shortenings, like tmw for tomorrow in text-speak. There’s also terms with a specific definition, like “string” means string of text (like a word or sentence). Just like a real language, the more you use it, the easier it is to remember.

    It can help too if you equate it with something you’re familiar with. So, if I’m comparing that calculator to a play, the parts that say “def something…end” are sort of like where there’s a list of characters and a little bit about them. I’m basically defining the character’s role in the play. Then later, where it says “call methods”, when I type the method’s name, it’s like the character entered the scene. I can give those characters lines to say too (which are orange in the pic).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s