1

I understand how to make lists with the Select function and NestList, but these are only for one dimensional lists. Is it possible to make lists of all points that satisfy a constraint? For example, all points {x,y} that satisfy PrimeQ[x*y+1]==True.

Sorry if this is really amateur, I only recently started Mathematica and I'm trying to teach myself the functions.

yohbs
  • 7,046
  • 3
  • 29
  • 60
volcanrb
  • 373
  • 1
  • 5

1 Answers1

2

There are many ways to do this. I will show one with SparseArray.

matrix = SparseArray[{x_, y_} /; PrimeQ[x y + 1] -> 1, {100, 100}]

Now try these:

MatrixPlot[matrix]

ArrayRules[matrix]

Keys@Most@ArrayRules[matrix]

The last one just gives a list of {x,y} pairs.

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263