# Reduce[] results filtering

I just started using mathematica at school, so this is a newbie question. From a previous question i managed to get this:

ClearAll[x];
Reduce[505 == 500 + Mod[Mod[x, 66], 9], x, Integers]
(* Element[C, Integers] && (x == 5 + 66*C || x == 14 + 66*C ||
x == 23 + 66*C || x == 32 + 66*C || x == 41 + 66*C ||
x == 50 + 66*C || x == 59 + 66*C) *)


I know that the answer that i am looking for is x=5,000 But if i give this command:

 FindInstance[
C ∈
Integers && (x == 5 + 66 C || x == 14 + 66 C ||
x == 23 + 66 C || x == 32 + 66 C || x == 41 + 66 C ||
x == 50 + 66 C || x == 59 + 66 C), {x}, 10]


i get the results:

{{x -> 28157}, {x -> -27112}, {x -> 18353}, {x -> -8275}, {x ->
3644}, {x -> 4613}, {x -> 32957}, {x -> -24415}, {x -> -21004}, {x -> 2342}}


Where is my x=5000 solution? How can i tell mathematica to give me only the solutions for lets say x>0 && x<10000 ? Is this possible?

• FindInstance[ C \[Element] Integers && (x == 5 + 66 C || x == 14 + 66 C || x == 23 + 66 C || x == 32 + 66 C || x == 41 + 66 C || x == 50 + 66 C || x == 59 + 66 C) && 4000 < x < 6000, {x, C}]? – Feyre Feb 7 '17 at 20:18
• FindInstance[ C [Element] Integers && (x == 5 + 66 C || x == 14 + 66 C || x == 23 + 66 C || x == 32 + 66 C || x == 41 + 66 C || x == 50 + 66 C || x == 59 + 66 C) && 0 < x < 6000, {x, C}, 20] Why is not showing my 5000 solution!?!? – Ray Feb 7 '17 at 20:26

## 1 Answer

If you're only interested in results in a certain range, you can try using Solve instead, and adding the condition to the expression, like so:

ClearAll[sol, vals, x];
sol = Solve[505 == 500 + Mod[Mod[x, 66], 9] && 0 < x < 10000, x, Integers];


I'm suppressing output because there's a lot of it!

Length@sol
(* 1061 *)


Note that Solve returns solutions as rules. Here are the first five:

Take[sol, 5]
(* {{x -> 5}, {x -> 14}, {x -> 23}, {x -> 32}, {x -> 41}} *)


We can get the list of values using ReplaceAll:

vals = x /. sol;
Take[vals, 5]
(* {5, 14, 23, 32, 41} *)


We can check to make sure that $5000$ is indeed a solution:

MemberQ[vals, 5000]
(* True *)

• Pillsy, thanks...Again!!! – Ray Feb 7 '17 at 20:39