What is the simplest function that generates a list of primes before an argument? Itβs not difficult to come up with such a function, for example:
foo[n_] := Block[{A = {}, p = 2}, While[p < n, A = Append[A, p]; p = NextPrime[p]]; A]
However, this seems too dirty. I would like to do something like
foo[n_] := Table[Prime[i], {i,2,???}]
Where??? is the NextPrime[n,-1] index NextPrime[n,-1] . Is it possible?
source share