Problem 3
Question:
Revelation 13.18:"Let him that hath understanding count the number of the beast, for it is the number of a man and his number is 666." Show that the sum of the squares of the first seven primes is the beast number.(Hint:see the Prime and Total functions.)
Answer:
(a)
One way is to use Range to create the integers {1,2,3,4,5,6,7}, then Prime on that to get a list of primes, then ^2 to square them, and finally Total to add 'em all up. Boom.
(b)
Another way is to use the Sum function, which is like an explicit loop. Either Sum[Prime[i]^2,{i,1,7}] or using standard mathematical notation from the palette :
(c)
Finally, while this is a bit outside the scope of where we are, one person ran into the subtle point of the difference between Plus and Total : one takes a list, and one takes many arguments. Note that Total only takes one argument - a list.
Suppose you had constructed a list, and wanted to use Plus to add 'em up? In other words, can you do something like what Total does if you don't have a function like that? Well, the answer is yes - several ways, in fact - but you have to do more work.
One way is to have an explicit running total which is updated while you loop over the list. This is what most programming languages would do.
A second way, which is probably more unfamiliar to most people, is to use Mathematica's "everything is a list" mentality, and explicitly turn {1,2,3,4}, which is really List[1,2,3,4], into Plus[1,2,3,4]
Created by Mathematica (September 13, 2004)