Do me favor and open up a web browser and type in google.com/foobar.
In this video I'll explain how I stumbled across this secret Google website.
About two years ago I was working on a project for work and I needed to write quite a bit
of python code.
I was still learning the syntax so I spent a lot of time Googling python questions.
After a couple of months working on this project something bizarre happened.
It was a Friday afternoon and I was sitting at my desk typing a python question into Google.
When I hit enter, instead of seeing my search results come up, the entire browser page flipped
over and revealed a black command prompt with the words "you're speaking our language.
Up for a challenge?"
My heart skipped a beat.
All of the sudden I felt like I was Matthew Broderick in the 1983 movie War Games and
I had accidentally stumbled onto a military computer.
I enthusiastically clicked the "I want to play" button and was brought to a screen that
looks like this.
Lucky for me this wasn't a computer named Joshua determined to end civilization using
Global Thermonuclear War.
What I had actually found was Google foobar, a secret Google recruiting tool where users
complete various coding challenges.
They had been following my python related searches and reached out to me with an exclusive
invitation to solve these coding challenges.
I had no idea what I was looking at, but it looked like a regular UNIX command line which
I'm familiar with.
So I typed in the list command and found a single text file called start_here.txt.
I used the cat command to see the contents of that text file.
I remember thinking this was clever because whoever receives this invite needs to know
basic Unix commands in order to navigate around.
The text file gave me two useful hints, the request command and of course the help command.
I typed in help to see a full list of commands.
Reading through these commands it was clear that I needed to request a new challenge and
write my source code in a new text file.
I could use the verify command to test my code, then submit it when I was happy with
it.
I requested the first challenge and a timer popped up on the screen telling me that I
had 24 hours to finish this challenge.
My heart began to race again!
This was so cool!
I had the choice between Java and Python as the language to write my programming solution.
I have very little experience in Java, so Python was my obvious choice.
The challenge went something like this.
Professor Boolean is an evil villain whose up to no good.
It was my job to help bring her down.
The chain of command is structured in such a way that each leader has at most 7 people
working directly under him/her.
The task is to write a function that returns the number of people in P.B.'s workforce given
the number of levels of hierarchy.
For example if there were only one level of hierarchy, there would be 8 total people in
the work force.
Professor Boolean and 7 leaders working directly under her.
If there were 2 levels, there would be 57 total people.
A quote that is often incorrectly attributed to Albert Einstein came to mind.
"If I had one hour to save the world, I would spend 55 minutes defining the problem and
5 minutes solving it".
I was given 24 hours to save the world from the fictitious villain Professor Boolean.
If you're adventurous, pause the video here and think about how you would solve the problem.
Feel free to write your solution in the comments.
I think it's fascinating to see the different ways people solve problems.
My approach was to get a piece of paper and start drawing diagrams.
I drew Professor Boolean at the top level with seven people below her.
Then I drew seven more people below each of those and so on.
After 2 levels I was tired of drawing people.
Based on my math experience I figured that exponents would play some part in the solution.
We know from the problem statement that there is only one person at the top level, Professor
Boolean.
We need way to mathematically describe this number.
If you remember how exponents work, any number raised to the power of zero is simply 1.
So we can describe the number of people in the top level as 7 raised to 0 which equals
1.
The number of people in the next level can be described as 7 raised to 1 which equals
7.
If we continue this trend the number of people in the 2nd level is 7^2 which is 49, and the
number of people in the 3rd level is 7^3 which is 343.
If the variable i represents a specific hierarchical level, we can describe the number of people
in level i as 7 raised to i.
For example in level 5 we know that there are 7 raised to 5, which is 16,807 people.
At this point given the number of levels, we've figured out a way to describe the number
of people at each level.
To calculate the total number of people in Professor Boolean's organization we just need
to add up all of the people at each level!
I'm not a mathematician but if I were I'd describe the total number of people in Professor
Boolean's evil organization as the following equation.
The summation of 7 raised to i where i varies from 0 to x.
I'm also not a programmer but if I were I would write a simple function that could calculate
the total number of people.
The argument (or input) to my function would be the number of levels and the function would
return the total number of people.
First I'll define a function that takes the argument x and returns x as the result.
This isn't a very useful function.
Next I'll create a variable called total which will keep track of the total number of people.
I'll set total equal to zero for now and have the function return total instead.
If I were to run this function now it would simply return zero.
As I discussed earlier the main calculation I want to perform is adding the results of
7 raised to 0, 7 raised to 1, 7 raised to 2, and so on until we get to 7^x.
For now let's set total equal to 7 raised to x.
Now we have a function that's actually taking a number x, doing something to it, and spitting
out a different number.
To get the total number of people who work for Professor Boolean we want to add the number
of people at each level.
In programming a common way to repeat some code over and over is using a "while loop".
To help construct the while loop I'll create another variable called level which represent
the current hierarchical level and set it equal to 0.
I can set up a while loop and give it the condition while(level<=x).
This will cause the loop to continue to execute over and over until level is greater than
x.
We'll tweak our calculation to say total is equal to total plus 7 raised to level.
Finally we want to increase the level by one each time we go through the loop so we say
level equals level+1.
Every time this loop executes, the number of people at the current level is calculated
then added to the previous total.
Once that is done the level is incremented.
This will continue until the level is greater than x at which point we exit the while loop
and the function returns the total number of people.
There are a couple of things I could clean up here like taking advantage of some shorthand
syntax.
We can change these two lines to their shorthand versions which makes the code a bit cleaner
and easier to read.
I copy and pasted my code into Google Foobar and ran the verify command which runs several
test cases.
My function passed all the tests and I submitted my code with more than 23 hours still on the
clock.
I spent the next few weeks requesting new challenges from Foobar and had a lot of fun
figuring them out.
I got stumped on one or two of them and failed to complete them before the countdown clock
ran out.
After I had complete about a dozen or so challenges Foobar congratulated me on my progress and
asked if I would like to share my contact information with a Google recruiter.
I gave my consent and received this email a few days later.
Since then I've talked to several Google recruiters about potential jobs.
Unfortunately most of their positions are for software developers, and I'm more interested
in embedded electronics and hardware development.
So Google, if you're out there listening, let me know if you have any hardware job openings
in my area!
If you have never written any code I would really encourage learning at least a little
bit.
Learning a few programming concepts will help your logical reasoning and problem solving
skills.
And I can promise you that learning to program is not as hard as you think it is.
There has never been an easier time to learn.
There are so many great tools available for free online.
I would highly recommend using Codecademy.
I have spent hours and hours learning to program through their curriculum and it's by far the
best free resource I've found on the web.
I'm not being paid to say that either, I have actually used it and believe in their product.