Google recently added a cool calulator
Simply enter a math formula like "5 *
5" into Google and it will return a results page with the answer.
Asking Google: "The
answer to life, the universe and everything" returns the calculator and the answer 42,
based on the calculation by Deep Thought, the super computer in the Douglas Adam's classic
"Life the Universe and Everything".
Google also links to a Wikipedia
entry that explains how 6 * 9 = 42 (hint: not base 10) and how code written
in C using macros also correctly multiplies 6*9=42. I also work in building
42 which makes it that much more special :)
Another cool feature I discovered is that Google does factorials. Entering 4! and
you'll see 4*3*2*1 (x * x-1) or 24. This reminded me of French mathematician
Blaise Pascal who's Pascal triangle solves probabability questions. For example, look
at the triangle below:
1 1 1
2 1 2 1
3 1 3 3 1
4 1 4 6 4 1
5 1 5 10 10 5 1
6 1 6 15 20 15 6 1
The numbers horizontally represents the possibilities of elements being picked.
Let's use the 4th row and letters A, B, C, D as examples. The fourth row represents
the numbers 1, 4, 6, 4, 1 which represent the probability of choosing 0, 1, 2, 3,
and 4 of the letters. Let's look at each of these:
0 - There is only one option for picking none of the letters.
1 - Since there are four unique letters, there are four unique possibilities.
2 - There are six ways of picking exactly two letters: AB, AC, AD, BC, BD, CD.
3 - There are four ways of picking three out of the four elements, simply choose which
letter you are not going to pick.
4 - There is only one way to select all of the letters.
Whew, with that explained, we can look at the mathematical formula for this:
N!/(R!(N!-R!)) where N represents the number of elements and R represents the number
Using our example above, where N is 4 and we'll set 2 as the number of matches,
Google correctly answers this as 6, matching the value in Pascal's triangle.
If you didn't have Google, you can represent Pascal's formula in C#
with the code below:
private static long fac(long x)
x *= i;
public static long Pascal(long n, long r)
return fac(n)/(fac(r) * fac(n-r));
Another interesting mathematical pattern in Pascal's triangle is the Fibonacci sequence
on the triangle diagonals.
Cool stuff, now do we call Google's calculator a web service?