I'm having some trouble in the following exercise:
Find which elements of the list are prime numbers or divisible by 3.
list = Table[i^2 - 6 i - 1, {i, 0, 15}]
my attempt: Cases[list, Divisible[_,3]]. Mathematica didn't like this and I don't know how to write it correctly :/
For prime numbers, I used Cases[list, _?PrimeQ] and it gave me the right answer, but I can't imagine a way to use incorporate the "or" thing, except by using a If. Is there a more imperative way of doing this?
Select[]might be more straightforward for you. – J. M.'s missing motivation Aug 30 '15 at 16:10Cases[list,x_/;Or@@{Divisible[x,3],PrimeQ[x]}]– N.J.Evans Aug 30 '15 at 16:16PrimeQmyTest[x]:=Or@@{Divisible[x,3],PrimeQ[x]}; Cases[list,_?myTest]– N.J.Evans Aug 30 '15 at 16:21