# Question:procedure with lists

## Question:procedure with lists

Maple 2020

Hello, I was given the problem "Set N:=100. (i) Form four lists L[1], L[3], L[5], L[7] where L[r] contains all primes 2< p < N such that p mod 8 = r ." and came up with the following code:

N := 100;
List1 := [];
List3 := [];
List5 := [];
List7 := [];
for p from 2 to N do
if isprime(p) and p mod 8 = 1 then List1 := [op(List1), p]; end if;
if isprime(p) and p mod 8 = 3 then
List3 := [op(List3), p];
end if;
if isprime(p) and p mod 8 = 5 then
List5 := [op(List5), p];
end if;
if isprime(p) and p mod 8 = 7 then
List7 := [op(List7), p];
end if;
end do;
List1;
List3;
List5;
List7;

this gave me the answer I wanted, however using the above code I have to answer this second question:

In the notation of Problem 1, make a procedure with input = arbitrary  positive integer N and output = the list [nops(L[1]), nops(L[3]), nops(L[5]), nops(L[7])]. Do some experiments to see for which (if any) r, L[r] is largest.

I am unsure of how to create a procedure out of the code I already have. I created this:

restart;
F := proc(n)

local N, p, List1, List3, List5, List7;

List1 := [];

List3 := [];

List5 := [];

List7 := [];

for p from N do

if isprime(p) and p mod 8 = 1 then List1 := [op(List1), p]; end if;

if isprime(p) and p mod 8 = 3 then List3 := [op(List3), p]; end if;

if isprime(p) and p mod 8 = 5 then List5 := [op(List5), p]; end if;

if isprime(p) and p mod 8 = 7 then List7 := [op(List7), p]; end if;

return [nops(List1), nops(List3), nops(List5), nops(List7)];

end do;

end proc;

however, when I input F(100) or any other value of N, I am receiving the error message "Error, (in F) initial value in for loop must be numeric or character"

Any ideas on how to improve my program to get the output I desire?

thank you

﻿