Skip to main content
2 of 3
added 520 characters in body
celtschk
  • 4.7k
  • 2
  • 23
  • 21

Wolfram Language (Mathematica), 33 26 bytes

I just noticed that for no integer solution, the output is undefined instead of empty list; that allows to remove a few bytes.

x/.Solve[#==0,x,Integers]&

Try it online!

Now if no integer solution exists, the function returns x.

Previously:

x/.Solve[#==0,x,Integers]/.x->{}&

Try it online!

celtschk
  • 4.7k
  • 2
  • 23
  • 21