Skip to main content
9 votes

Make a list of the first 100 primes, keeping only ones whose last digit is less than 3

SolveValues[x <= Prime[100] && Mod[x, 10] < 3, x, Primes] ...
kglr's user avatar
  • 396k
9 votes
Accepted

Confused about If statement

Translation to make it easier to see. When you write If[n1 == 0, n2 == 1] This translates to ...
Nasser's user avatar
  • 145k
8 votes
Accepted

Make a list of the first 100 primes, keeping only ones whose last digit is less than 3

Well, since the cat's out of the bag, I guess we can proceed with our race-toward-ten. I'll provide a point-free solution to the original problem and avoid the OP's question about the specific ...
lericr's user avatar
  • 28.9k
8 votes

Problem with If statement

masters = {C18[1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0], C18[1, 1, 1, 1, 1, 1, 0, 1, 1, 2, 0, 0]}; C18 is an undefined function. ...
Bob Hanlon's user avatar
  • 159k
6 votes
Accepted

Condition inside pure function

As supplement of @MichaelE2's comment. Condition is bit of "meta" in the sense that it will only be absorbed by specific functions with pattern matching ...
Lacia's user avatar
  • 2,263
6 votes

Make a list of the first 100 primes, keeping only ones whose last digit is less than 3

Expanding on my comment (first method) 1. Select[Prime[Range[100]], Mod[#, 10] < 3 &] here are two more (kind of cheating because 2 is an exception) 2. <...
ydd's user avatar
  • 3,810
6 votes
Accepted

Which NDSolve method is most effective for the given chaotic system?

We don't know what method is most efficient, since to answer this question we need too much test performed. We can only suggest code without some NDSolve messages ...
Alex Trounev's user avatar
5 votes

Make a list of the first 100 primes, keeping only ones whose last digit is less than 3

Another option using what the question asks, which is to use f[#] p = Prime[Range[100]] ...
Nasser's user avatar
  • 145k
5 votes

Adapt elements in the list, condition by condition

box[1, 1] = {{4.4, {1, 1}, {a}}, {1.5, {1, 1}, {a}}, {10.8, {2, 1}, {3 a}}, {10, {1, 3}, {4 a}}}; box[1, 1] /. {{a} -> {1}, a -> .1} ...
kglr's user avatar
  • 396k
5 votes
Accepted

How to check if the given row matches one of the rows of a table?

tabb = RandomInteger[{0, 4}, {5, 4}]; row = RandomInteger[{0, 4}, 4]; Well, it's simply MemberQ[tabb, row] returning ...
eldo's user avatar
  • 74.1k
4 votes

Make a list of the first 100 primes, keeping only ones whose last digit is less than 3

Just to illustrate Sow and Reap ...
ubpdqn's user avatar
  • 61.5k
4 votes
Accepted

SetDelayed assignment not producing expected result when using ReplaceAll

Well, the simplest thing to do would be to use Equal instead of SameQ: test[k_, x_] := If[k == 0, x, x^2] It would also work to put a constraint on your argument ...
lericr's user avatar
  • 28.9k
4 votes

SetDelayed assignment not producing expected result when using ReplaceAll

See Operator Precedence in Tech Note Operator Input Forms test[k_, x_] is evaluating before the ReplaceAll. In ...
Edmund's user avatar
  • 42.3k
4 votes

How to check if the given row matches one of the rows of a table?

SeedRandom[1]; tabb = RandomInteger[{0, 4}, {5, 4}] row = {0, 3, 4, 4} ContainsAny[tabb, {row}] True
Syed's user avatar
  • 55.3k
4 votes

How to check if the given row matches one of the rows of a table?

Another alternative is to use Union: ...
E. Chan-López's user avatar
4 votes

Pattern matching vs. condition in a function

For g4, your condition doesn't evaluate to True or False. Specifically, ...
lericr's user avatar
  • 28.9k
4 votes

How to highlight top N elements in each table column?

As an example in: Using Highlighted and Ordering: ...
Syed's user avatar
  • 55.3k
4 votes
Accepted

Evaluation control of nested With, If and Integrate

After a second thought I retract my vote for duplicate because the relevance is probably not so obvious at least for beginners, but do remember this post is essentially duplicate of the following: Why ...
xzczd's user avatar
  • 66.7k
4 votes

Evaluation control of nested With, If and Integrate

Evaluation process in Mathematica can be tricky at the beginning; I suggest reading the tutorial on the Evaluation of Expressions. The problem you are facing is that both ...
Domen's user avatar
  • 26.2k
3 votes

Modify list elements if last two entries are equal

list = {{1, 1, 1, 1, 1, 3}, {1, 1, 3, 4, 1, 1}}; Using SequenceReplace (new in 11.3) and ...
eldo's user avatar
  • 74.1k
3 votes

Removing "spikes" in data

data = Table[Evaluate @ Re @ FourierSeries[t^5, t, 4], {t, -3. Pi, 3. Pi, 6. Pi/128}]; Using GaussianFilter ...
eldo's user avatar
  • 74.1k
3 votes

Check an input matrix M contains any nonzero diagonal matrix element or not

p = {{-1, 1, 1}, {2, 0, 2}, {3, 3, 1}}; q = {{0, 1, 1}, {2, 0, 2}, {3, 3, 0}}; 1. Using AllTrue with ...
eldo's user avatar
  • 74.1k
3 votes

Using "If" statement to change a list values

Function[{x,y},If[x<60,y+20,y],Listable][Sample,Sample2] (* {25,10,35,20} *)
user1066's user avatar
  • 19.3k
3 votes

Extracting data from a table under conditions

Using kglr's data: tb1 = {{0, 3}, {0, 0}, {1, 3}, {2, 0}, {2, 0}, {0, 0}, {1, 1}, {2, 2}, {1, 0}, {3, 3}}; Another way, using ...
E. Chan-López's user avatar
3 votes

Extracting data from a table under conditions

Some other possibilities Using kglr's data: list = {{0, 3}, {0, 0}, {1, 3}, {2, 0}, {2, 0}, {0, 0}, {1, 1}, {2, 2}, {1, 0}, {3, 3}}; Predefine ...
eldo's user avatar
  • 74.1k
3 votes

SetDelayed assignment not producing expected result when using ReplaceAll

Okay, first I'll acknowledge @att's comment. Using Unevaluated is probably the most aligned with what you were trying to achieve with your original code. Maybe I'm ...
lericr's user avatar
  • 28.9k
3 votes

How to check if the given row matches one of the rows of a table?

tabb = { {1, 0, 4, 0}, {4, 1, 2, 1}, {0, 3, 3, 4}, {2, 0, 4, 1}, {3, 0, 3, 4}}; row = {2, 0, 4, 1}; Three more simple methods ...
eldo's user avatar
  • 74.1k
3 votes
Accepted

How to check if at least one ordering of the given row matches one of the rows of a table?

MemberQ[Sort /@ tabb, Sort[roww]]
Domen's user avatar
  • 26.2k
3 votes

How to highlight top N elements in each table column?

For your example, we may first determine the position (row: pos of the largest element in each column (accounting for the header). Then we add the row number to pos, again accounting for the header. ...
Daniel Huber's user avatar
  • 52.6k
3 votes

How to highlight top N elements in each table column?

We can use Dataset with custom functions as option settings for ItemStyle and Background: <...
kglr's user avatar
  • 396k

Only top scored, non community-wiki answers of a minimum length are eligible