Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am struggling with a Project Euler problem with Mathematica, what I want to do is to Replace a list like this {5,6,x,x,3} with the rule {x -> i} to {5,6,0,0,3}, {5,6,1,1,3}etc,and here is my code:

countP[l_list] := Select[
FromDigits /@ Table[Evaluate[l /. {x -> i}], {i, 0, 9}], PrimeQ] //
Length

countP[{5, 6, x, x, 3}]

it turns out not working.but when I try the code below,

Select[
FromDigits /@ Table[{5, 6, x, x, 3} /. {x -> i}, {i, 0, 9}], 
PrimeQ] // Length

It works, and return a value 7 What's wrong with the first code? and how can I deal with it ?

share|improve this question

closed as too localized by m_goldberg, Sjoerd C. de Vries, Michael E2, rm -rf May 4 '13 at 15:57

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
It should be l_List. Capitalization matters. –  J. M. May 4 '13 at 1:26
    
Thank you so much, It works. –  tintin May 4 '13 at 1:30
    
You should be allowed to answer your own question in a few hours... –  J. M. May 4 '13 at 2:49
    
btw, your table generation can be made slightly more compact, Table[{5, 6, i, i, 3}, {i, 0, 9}], or {5, 6, #, #, 3} & /@ Range[0, 9] –  Aky May 4 '13 at 3:57
    
Thanks,I'll try that. –  tintin May 4 '13 at 9:39

1 Answer 1

I just got a little mistake with my code. The countP[l_list] should be :

countP[l_List]
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.