Prime Numbers, those curious digits that are divisible only by the number 1 and by themselves. Mathematicians and other sundry geeks have long been fascinated with these oddities. Just yesterday, NBC News ran a story that the current largest prime number ever discovered is more than 22,000,000 digits long! (Ummm, and how many football fields long would that be?...).
In Excel, you can test to see if a number is Prime by creating a Custom Function called ISPRIME (pretty geeky!) with the following VBA code:
Function ISPRIME(num As Long) As Boolean
num_root = Sqr(num) + 1If num < 2 Then
ISPRIME = False
ElseIf num = 2 Or num = 3 Then
ISPRIME = True
ElseIf num Mod 2 = 0 Or num Mod 3 = 0 Then
ISPRIME = False
Else
For i = 6 To num_root Step 6
If num Mod (i - 1) = 0 Or num Mod (i + 1) = 0 Then
ISPRIME = False
Exit Function
End If
Next
ISPRIME = True
End If
End Function
Taking this a step further, we can explore Mersenne Prime Numbers. A Mersenne number is in the form of Mn=(2^n)-1. Although Excel does not have sufficient power to do this in great depth, it is fun to see what can be done with our favorite spreadsheet software.
With the assumption that you have a Bit O’ Geek in you, here is what you can do.
1. Create a simple spreadsheet with a similar format to the following starting in A1:
2. Starting in A3, insert consecutive numbers starting with 2 into Column A.
3. In B3, place the formula, =(2^A3)-1 and copy down with relative references
4. Lastly, use the custom ISPRIME function starting in C3 to determine if the numbers in Column B are prime
Whether you find this Cool or not will be a factor of your individual Geekiness. If you are like me (you poor soul…) you may well find this Totally Rad!
No comments:
Post a Comment