Here's what I have...
Select[roll, # <= 3 &]
Now, the list that follows may have one 3 or two three's. I want it to stop at the first three from left to right.
Mathematician trying to code.
Here's what I have...
Select[roll, # <= 3 &]
Now, the list that follows may have one 3 or two three's. I want it to stop at the first three from left to right.
Mathematician trying to code.
Note: I removed my original posting, which was basically like that of belisarius. Here's another try...
If you are sure that the number 3 is a member of
roll
then this should work:This is equivalent to:
If you cannot make this assumption, just test first with
MemberQ
EDIT: Credit goes to TomD for suggesting the +1 in the second solution, which eliminates the need to use
Append
.You could try something like:
Usage:
If you also want to filter values greater than 3, you may just use your code wrapping mine:
so:
This is an order of magnitude faster than
TakeWhile
on a list of integers.To get the list through 3, just use
{x, 3}
on the right hand side.