I am attempting to implement the Sieve of Sundaram:
Start with the list of integers 1,2,...,n. For every pair of integers (i,j) satisfying 1<=i<=j and i+j+2ij<=n, remove the number i+j+2ij from the list. Take all the numbers still in the list: double them and add 1 to each. This results in a list of all the odd primes below 2n+2.
Here's the code I wrote:
sundaram[n_Integer] := [ Do[i = 1, n, 1, Do[j = 1, n, 1, If[i + j + 2*j*i <= n, AppendTo[list1, i + j + 2*j*i], Break]; If[MemberQ[list1, i], Break, AppendTo[list2, 2*i + 1]] ] ]; Select[list2] ]
I am unable to make sense of these errors. I'd like to know how I can fix the syntaxes in my module.