Find a binary needle in a decimal haystack
05AB1E, 10 8 bytes
Takes the needle in binary to save 1 byte.
-2 bytes thanks to Emigna
œJÙʒbŒIå
Try it online!
œJÙʒbŒIå Arguments: a, n
œJÙ Get all unique permutations of a
ʒ Filter: Keep if following code returns true
b Convert to binary
Œ Get all substrings
Iå Check if substrings contain n
Implicit output of filtered list
Python 2, 90 bytes
-3 bytes thanks to @Gábor Fekete
Try it online
Takes as input array of strings, representing ints from hay and string, representing needle in binary
from itertools import*
lambda H,N:{i for i in permutations(H)if N in bin(int(''.join(i)))}
Java 10, 320 312 305 297 292 bytes
import java.util.*;Set s=new HashSet();l->n->{Long q=0;p(l,0);for(var x:s)if(q.toString(q.decode(x+""),2).contains(n))System.out.println(x);}void p(List l,int k){int i=k,x=l.size();for(Collections C=null;i<x;p(l,k+1),C.swap(l,k,i++))C.swap(l,i,k);if(k>x-2)s.add((l+"").replaceAll("\\D",""));}
Input as List & binary-String, output as Strings on new-lines.
Explanation:
Try it here.
import java.util.*; // Required import for Set, HashSet, List, and Collections
Set s=new HashSet(); // Class-level Set
l->n->{ // Method (1) with List and String parameters and no return-type
Long q=0; // Number-object is required for two static method-calls below
p(l,0); // Determine all permutations of given list and put it in the Set
for(var x:s) // Loop over these permutations
if(q.toString(q.decode(x+""),2)
// If the binary String of the current permutation
.contains(n)) // contains the binary String of the input integer
System.out.println(x);} // Print this permutation
void p(List l,int k){ // Method (2) with List and integer parameters and no return-type
int i=k,x=l.size(); // Two temp integers
for(Collections C; // Collections-object is required for two static method-calls below
i<x // Loop `i` in the range [`k`, list-size)
; // After every iteration:
p(l,k+1), // Do a recursive-call to this method with `k+1`
Collections.swap(l,k,i++))
// And swap the items at indices `k` and `i` back
Collections.swap(l,i,k); // Swap the items at indices `i` and `k`
if(k>x-2) // If `k` is now equal to the size of the list - 1
s.add((l+"").replaceAll("\\D",""));}
// Add this permutation to the Set