You start a rumor by telling it to n people and each of them tells it to another n-1 people. If each of these people, in turn, tells the rumor to another n-2 people, and so forth with no person hearing the rumor from more than one source, find a closed-form expression (in terms of n) for the total number of people that have been told the rumor.
The following program keeps track of how many people are told in each generation of tellees (gen = previous generation size times the reduced number from n), and the overall number of people who have been told (told).
CLS
DEFDBL A-Z
FOR n = 1 TO 17
gen = n: told = n
FOR n1 = n - 1 TO 1 STEP -1
gen = gen * n1
told = told + gen
NEXT
PRINT USING "## ############### "; n; told
NEXT
The resulting table is:
1 1
2 4
3 15
4 64
5 325
6 1956
7 13699
8 109600
9 986409
10 9864100
11 108505111
12 1302061344
13 16926797485
14 236975164804
15 3554627472075
16 56874039553216
17 966858672404689
As a manual check for, say 4:
You tell 4 people total 4 so far
4 people tell 3 people each, making 12 16
12 people tell 2 people each, making 24 40
24 people tell 1 person each, making 24 64
Looking up the sequence in Sloane finds Sloane A007526, where a simple formula is given:
[e*n! - 1] where the square brackets indicate the floor function, or integer part: the greatest integer not exceeding the argument enclosed.
The following program calculates that formula and places it in a column to the right, for comparison.
CLS
DEFDBL A-Z
e = EXP(1)
nf = 1
FOR n = 1 TO 17
nf = nf * n
gen = n: told = n
FOR n1 = n - 1 TO 1 STEP -1
gen = gen * n1
told = told + gen
NEXT
PRINT USING "## ############### ###############"; n; told; INT(e * nf - 1)
NEXT
1 1 1
2 4 4
3 15 15
4 64 64
5 325 325
6 1956 1956
7 13699 13699
8 109600 109600
9 986409 986409
10 9864100 9864100
11 108505111 108505111
12 1302061344 1302061344
13 16926797485 16926797485
14 236975164804 236975164804
15 3554627472075 3554627472075
16 56874039553216 56874039553216
17 966858672404689 966858672404689
The columns do match, verifying the closed-form expression.
|
Posted by Charlie
on 2008-04-25 16:09:17 |