Skip to main content
1 of 5
minhthien_2016
  • 4.7k
  • 1
  • 14
  • 31

How can I reduce the time to run this code?

I am trying to find the numbers $a$, $b$, $c$, $d$, here $a,b,c,d \in [-15,15]$ and difference from $0$ so that the equation $\left |x^2 + a x + b \right | = c x + d$ has four distinct integeral solutions difference from $0$. I tried

ClearAll[a, b, c, d];
    sol = x /. Solve[{Abs[x^2 + a x + b] == c x + d} , x, Reals];
    ClearAll[f];
    (f[{a_, b_, c_, d_}] := 
        Quiet@Check[And @@ (IntegerQ /@ #), False]) &[sol]
    poss = Select[
       Tuples[Range[-15, 
         15], {4}],  #[[1]] #[[2]] #[[3]] #[[4]] != 
          0  && #[[1]]^2 - 4 #[[2]] > 0 && #[[2]]^2 - #[[4]]^2 != 0 && 
         f[#] &];
    Take[poss, Length[poss]];
    With[{s = sol}, 
     getSolution[poss_] := Block[{a, b, c, d}, {a, b, c, d} = poss;
       Join[poss, s]]]
    getSolution /@ poss

and got 426 solutions. But the time is about 15 minutes. How can I reduce the time?

minhthien_2016
  • 4.7k
  • 1
  • 14
  • 31