I'm currently doing a unit at university that touched briefly on Mathematica, but the final exam will feature multiple choice questions from Mathematica (along with excel and matlab). This leads to this question
Range[10] /. {x_ /; PrimeQ[x] -> x^2}
What does this actually do? I plugged it into Mathematica, and it gave me
{1, 4, 9, 4, 25, 6, 49, 8, 9, 10}
as its output.
I lack the understanding of what each part of the input does as I never came across this earlier in my studies.
x2, you really meant to sayx^2, yes? Then all you're doing is replace any number that is prime with its square. – J. M.'s missing motivation Jun 08 '15 at 10:00x^2. – LLlAMnYP Jun 08 '15 at 10:20Range[10] /. {x_?PrimeQ -> x^2}– Bob Hanlon Jun 08 '15 at 11:26