Skip to main content
added 215 characters in body
Source Link
jVincent
  • 14.8k
  • 1
  • 44
  • 76

A straight forward approach is to simply generate all the combinations you don't want and use Complement to remove them from all the possible numbers. You can generate all possible combinations using Tuples:

 expandBinRep[n_]:=n//.{a___,x,b___}:>Sequence[{a,0,b},{a,1,b}]


 Complement[Tuples[{0, 1}, {8}], expandBinRep@{{x, x, x, x, 0, x, x, 1}}]

I would emphasise that this might lead you to deal with huge lists of numbers when it might not bee needed.

An alternative route might be to take the description of numbers to exclude {x,1,0,x} and generate descriptions that can generate remaining numbers, for this example; {x,0,x,x} and {x,x,1,x}. This is done simply by making one difference so it doesn't match and letting all other digits be free:

invertDescription[v_]:=Insert[ConstantArray[x,Length[v]-1],
     Abs[1 - v[[#]]],#]&/@ Flatten[Position[v,0|1]]

However with this definition the descriptions overlap, so you'd need Union to make them only appear once:

invertDescription[{x, x, x, x, 0, x, x, 1}] // expandBinRep // Union

Update

I believe that this definition solves the problem of overlapping patterns:

 invertDescription[v_] := 
   PadRight[Append[v[[1 ;; # - 1]], Abs[1 - v[[#]]]], Length@v, x] & 
       /@ Flatten[Position[v, 0 | 1]]

A straight forward approach is to simply generate all the combinations you don't want and use Complement to remove them from all the possible numbers. You can generate all possible combinations using Tuples:

 expandBinRep[n_]:=n//.{a___,x,b___}:>Sequence[{a,0,b},{a,1,b}]


 Complement[Tuples[{0, 1}, {8}], expandBinRep@{{x, x, x, x, 0, x, x, 1}}]

I would emphasise that this might lead you to deal with huge lists of numbers when it might not bee needed.

An alternative route might be to take the description of numbers to exclude {x,1,0,x} and generate descriptions that can generate remaining numbers, for this example; {x,0,x,x} and {x,x,1,x}. This is done simply by making one difference so it doesn't match and letting all other digits be free:

invertDescription[v_]:=Insert[ConstantArray[x,Length[v]-1],
     Abs[1 - v[[#]]],#]&/@ Flatten[Position[v,0|1]]

However with this definition the descriptions overlap, so you'd need Union to make them only appear once:

invertDescription[{x, x, x, x, 0, x, x, 1}] // expandBinRep // Union

 

A straight forward approach is to simply generate all the combinations you don't want and use Complement to remove them from all the possible numbers. You can generate all possible combinations using Tuples:

 expandBinRep[n_]:=n//.{a___,x,b___}:>Sequence[{a,0,b},{a,1,b}]


 Complement[Tuples[{0, 1}, {8}], expandBinRep@{{x, x, x, x, 0, x, x, 1}}]

I would emphasise that this might lead you to deal with huge lists of numbers when it might not bee needed.

An alternative route might be to take the description of numbers to exclude {x,1,0,x} and generate descriptions that can generate remaining numbers, for this example; {x,0,x,x} and {x,x,1,x}. This is done simply by making one difference so it doesn't match and letting all other digits be free:

invertDescription[v_]:=Insert[ConstantArray[x,Length[v]-1],
     Abs[1 - v[[#]]],#]&/@ Flatten[Position[v,0|1]]

However with this definition the descriptions overlap, so you'd need Union to make them only appear once:

invertDescription[{x, x, x, x, 0, x, x, 1}] // expandBinRep // Union

Update

I believe that this definition solves the problem of overlapping patterns:

 invertDescription[v_] := 
   PadRight[Append[v[[1 ;; # - 1]], Abs[1 - v[[#]]]], Length@v, x] & 
       /@ Flatten[Position[v, 0 | 1]]
added 111 characters in body
Source Link
jVincent
  • 14.8k
  • 1
  • 44
  • 76

A straight forward approach is to simply generate all the combinations you don't want and use Complement to remove them from all the possible numbers. You can generate all possible combinations using Tuples:

 expandBinRep[n_]:=n//.{a___,x,b___}:>Sequence[{a,0,b},{a,1,b}]


 Complement[Tuples[{0, 1}, {8}], expandBinRep@{{x, x, x, x, 0, x, x, 1}}]

I would emphasise that this might lead you to deal with huge lists of numbers when it might not bee needed.

An alternative route might be to take the description of numbers to exclude {x,1,0,x} and generate descriptions that can generate re remaining numbers, for this example; {x,0,x,x} and {x,x,1,x}. This is done simply by making one difference so it doesn't match and letting all other digits be free:

invertDescription[v_]:=Insert[ConstantArray[x,Length[v]-1],
     Abs[1 - v[[#]]],#]&/@ Flatten[Position[v,0|1]]

However with this definition the descriptions overlap, so you'd need Union to make them only appear once:

invertDescription[{x, x, x, x, 0, x, x, 1}] // expandBinRep // Union

 

A straight forward approach is to simply generate all the combinations you don't want and use Complement to remove them from all the possible numbers. You can generate all possible combinations using Tuples:

 expandBinRep[n_]:=n//.{a___,x,b___}:>Sequence[{a,0,b},{a,1,b}]


 Complement[Tuples[{0, 1}, {8}], expandBinRep@{{x, x, x, x, 0, x, x, 1}}]

An alternative route might be to take the description of numbers to exclude {x,1,0,x} and generate descriptions that can generate re remaining numbers, for this example; {x,0,x,x} and {x,x,1,x}. This is done simply by making one difference so it doesn't match and letting all other digits be free:

invertDescription[v_]:=Insert[ConstantArray[x,Length[v]-1],
     Abs[1 - v[[#]]],#]&/@ Flatten[Position[v,0|1]]

However with this definition the descriptions overlap, so you'd need Union to make them only appear once:

invertDescription[{x, x, x, x, 0, x, x, 1}] // expandBinRep // Union

 

A straight forward approach is to simply generate all the combinations you don't want and use Complement to remove them from all the possible numbers. You can generate all possible combinations using Tuples:

 expandBinRep[n_]:=n//.{a___,x,b___}:>Sequence[{a,0,b},{a,1,b}]


 Complement[Tuples[{0, 1}, {8}], expandBinRep@{{x, x, x, x, 0, x, x, 1}}]

I would emphasise that this might lead you to deal with huge lists of numbers when it might not bee needed.

An alternative route might be to take the description of numbers to exclude {x,1,0,x} and generate descriptions that can generate remaining numbers, for this example; {x,0,x,x} and {x,x,1,x}. This is done simply by making one difference so it doesn't match and letting all other digits be free:

invertDescription[v_]:=Insert[ConstantArray[x,Length[v]-1],
     Abs[1 - v[[#]]],#]&/@ Flatten[Position[v,0|1]]

However with this definition the descriptions overlap, so you'd need Union to make them only appear once:

invertDescription[{x, x, x, x, 0, x, x, 1}] // expandBinRep // Union

 
Source Link
jVincent
  • 14.8k
  • 1
  • 44
  • 76

A straight forward approach is to simply generate all the combinations you don't want and use Complement to remove them from all the possible numbers. You can generate all possible combinations using Tuples:

 expandBinRep[n_]:=n//.{a___,x,b___}:>Sequence[{a,0,b},{a,1,b}]


 Complement[Tuples[{0, 1}, {8}], expandBinRep@{{x, x, x, x, 0, x, x, 1}}]

An alternative route might be to take the description of numbers to exclude {x,1,0,x} and generate descriptions that can generate re remaining numbers, for this example; {x,0,x,x} and {x,x,1,x}. This is done simply by making one difference so it doesn't match and letting all other digits be free:

invertDescription[v_]:=Insert[ConstantArray[x,Length[v]-1],
     Abs[1 - v[[#]]],#]&/@ Flatten[Position[v,0|1]]

However with this definition the descriptions overlap, so you'd need Union to make them only appear once:

invertDescription[{x, x, x, x, 0, x, x, 1}] // expandBinRep // Union