Finite tilings in one dimension The purpose of this challenge is to determine if a collection of one-dimensonal pieces can be tiled to form a finite continuous chunk.

A piece is a non-empty, finite sequence of zeros and ones that starts and ends with a one. Some possible pieces are 1, 101, 1111, 1100101.

Tiling means arranging the pieces so that a single contiguous block of ones is formed. A one from one piece can occupy the place of a zero, but not of a one, from another piece.

Equivalently, if we view a one as being "solid material" and a zero as a "hole", the pieces should fit so as to form a single stretch, without leaving any holes.

To form a tiling, pieces can only be shifted along their one-dimensional space. (They cannot be split, or reflected). Each piece is used exactly once.

Examples

The three pieces 101, 11, 101 can be tiled as shown in the following, where each piece is represented with the required shift:

  101
11
   101


so the obtained tiling is

111111


As a second example, the pieces 11011 and 1001101 cannot be tiled. In particular, the shift

 11011
1001101


is not valid because there are two ones that collide; and

11011
  1001101


is not valid because the result would contain a zero.

Additional rules

The input is a collection of one or more pieces. Any reasonable format is allowed; for example:


A list of strings, where each string can contain two different, consistent characters;
Several arrays, where each array contains the positions of ones for a piece;
A list of (odd) integers such the binary representation of each number defines a piece.


The output should be a truthy value if a tiling is possible, and a falsy value otherwise. Output values need not be consistent; that is, they can be different for different inputs.

Programs or functions are allowed, in any programming language. Standard loopholes are forbidden.

Shortest code in bytes wins.

Test cases

Each input is on a different line

Truthy

1
111
1, 1
11, 111, 1111
101, 11, 1
101, 11, 101
10001, 11001, 10001
100001, 1001, 1011
10010001, 1001, 1001, 101
10110101, 11001, 100001, 1
110111, 100001, 11, 101
1001101, 110111, 1, 11, 1


Falsy

101
101, 11
1, 1001
1011, 1011
11011, 1001101
1001, 11011, 1000001
1001, 11011, 1000001, 10101
JavaScript (ES6), 74 73 70 bytes

Takes input as an array of 32-bit integers. Returns a boolean.

f=([n,...a],x)=&gt;n?[...f+''].some(_=&gt;n&amp;&amp;!(x&amp;n)&amp;f(a,x|n,n&lt;&lt;=1)):!(x&amp;-~x)


Or 66 bytes with inverted truthy/falsy values:

f=([n,...a],x)=&gt;n?[...Array(32)].every(_=&gt;x&amp;n|f(a,x|n,n*=2)):x&amp;-~x


Test cases



f=([n,...a],x)=&gt;n?[...f+''].some(_=&gt;n&amp;&amp;!(x&amp;n)&amp;f(a,x|n,n&lt;&lt;=1)):!(x&amp;-~x)

console.log('[Truthy]')
console.log(f([0b1]))
console.log(f([0b111]))
console.log(f([0b1,0b1]))
console.log(f([0b11,0b111,0b1111]))
console.log(f([0b101,0b11,0b1]))
console.log(f([0b101,0b11,0b101]))
console.log(f([0b10001,0b11001,0b10001]))
console.log(f([0b100001,0b1001,0b1011]))
console.log(f([0b10010001,0b1001,0b1001,0b101]))
console.log(f([0b10110101,0b11001,0b100001,0b1]))
console.log(f([0b110111,0b100001,0b11,0b101]))
console.log(f([0b1001101,0b110111,0b1,0b11,0b1]))

console.log('[Falsy]')
console.log(f([0b101]))
console.log(f([0b101,0b11]))
console.log(f([0b1,0b1001]))
console.log(f([0b1011,0b1011]))
console.log(f([0b11011,0b1001101]))
console.log(f([0b1001,0b11011,0b1000001]))
console.log(f([0b1001,0b11011,0b1000001,0b10101]))




How?

f = (                       // f = recursive function taking:
  [n, ...a],                //   n = next integer, a = array of remaining integers
  x                         //   x = solution bitmask, initially undefined
) =&gt;                        //
  n ?                       // if n is defined:
    [... f + ''].some(_ =&gt;  //   iterate 32+ times:
      n &amp;&amp;                  //     if n is not zero:
        !(x &amp; n)            //       if x and n have some bits in common,
        &amp;                   //       force invalidation of the following result
        f(                  //       do a recursive call with:
          a,                //         the remaining integers
          x | n,            //         the updated bitmask
          n &lt;&lt;= 1           //         and update n for the next iteration
        )                   //       end of recursive call
    )                       //   end of some()
  :                         // else (all integers have been processed):
    !(x &amp; -~x)              //   check that x is a continuous chunk of 1's