 |
|
List Archives > 
Maple User Group List Archive > 
Archive by date > 
This Month By Date > 
This Month By Topic
[MUG] fundamental idea in a procedure - counting primes
| [MUG] fundamental idea in a procedure - counting primes |
|
Author: John A Velling
Posted: Wed, 12 Feb 2003 15:23:37 -0500
|
>> From: "John A. Velling" />
I seem to be missing the point of procedures. Consider the following:
u := proc(k)
for counter from 0
while ithprime(counter+1) <= k
do counter := counter +1 od:
end proc;
The intention is to count the primes less than or equal to k. I get u(4) =1
and u(5) =3. Somehow I just don't understand what is being returned here
and why. Any suggestions?
What I really want is to make a list of all primes <= k. Here is my effort:
u := proc(k)
for counter from 0
while ithprime(counter+1) <= k
do counter := counter +1 od:
P := array(1..counter-1):
for n to counter-1
do P[n] := ithprime(n) od:
print(P)
end proc;
which indeed prints out the desired list. However a little testing
indicates that the result of u(100) is not the list of primes up to 100.
What am I missing and how can I make the procedure give an array as output?
Thanks,
John A. Velling
|
Previous by date: [MUG] Differentiation of an arbitrary sum, Ingo Ellersdorfer
Next by date: [MUG] What has MAPLE 7 against Mathematica 3?, Donohue
Previous thread: [MUG] easiest way to write, Maple User Group
Next thread: [MUG] What has MAPLE 7 against Mathematica 3?, Donohue
|
|
|