This is a question from an "Elementary Introduction to the Wolfram Language" Section 28: Tests and Conditionals. We are asked to "Make a list of the first 100 primes, keeping only ones whose last
digit is less than 3."
I think it should look something like this:
Select[Prime[Range[100]], f[#]<3 &]
where f[#] specifies a function that would select the last digit of each number.
However, I do not know how to create a condition on the last digit of a number?
Would somebody be able to help with this? Or point out where I've gone wrong so far. Thanks!
IntegerDigits
will give you a list of the digits that represent an integer. TheLast
function will give you the last element of a list. AndLessThan
will do a comparison for you. Try to put those together into a function. Come back with more questions if you still can't figure it out. $\endgroup$Mod
--that's simpler. But now you don't get to try it on your own. $\endgroup$Mod
instead of explicitly typing it all out $\endgroup$primes = GeneralUtilities`NewIterator[MyPrimeIterator, {n = 0, p = 0}, While[Mod[p = Prime[++n], 10] >= 3, Null]; p ]; GeneralUtilities`TakeIterator[primes, 100] // ReadList
$\endgroup$