About using Scan instead of Map when using Reap and Sow in @bmf's proposal
Using Map when using Reap and Sow:
(*My mate @bmf*)
Reap[If[PrimeQ[IntegerReverse[#]], Sow[#]] & /@
Select[PrimeQ][Range[5000]]][[2, 1]] // RepeatedTiming // First
(0.00932226)
UsingScan when using Reap and Sow:
Reap[Scan[If[PrimeQ[IntegerReverse[#]], Sow[#]] &,
Select[Range[5000], PrimeQ]]][[2, 1]] // RepeatedTiming // First
(0.0087359)
The times obtained above using RepeatedTiming for both Map and Scan are quite similar, indicating that the efficiency of both methods is comparable for this data size. It's important to note that the real advantage of using Scan instead of Map in this context is to avoid creating an unnecessary intermediate list, but the actual improvement in execution time may be minor.
That said, the choice to use Scan instead of Map in this case is not just about efficiency. It is also a design choice that reflects the intent of the code. By using Scan, we indicate that the list of results produced by applying the function doesn't matter and that only the side effect is of interest (in this case, the seeding process with Sow).
In practice, for problems of this size, the execution time difference between Map and Scan is smaller. However, as the problem scales or is integrated into more complex code, these design decisions can have more significant implications for both efficiency and readability.
941, which is a prime-palindromic number. So, I am suspicious of the code. – Lawerance Jul 31 '14 at 06:34941. – Lawerance Jul 31 '14 at 06:43941is because941reversed is149and these are not the same (the meaning of Palindromic). So your approach is actually wrong. – RunnyKine Jul 31 '14 at 06:51941is not a palindrome. Your definition differs from the previous question. – Mr.Wizard Jul 31 '14 at 06:51