Skip to main content
saved 1 byte
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 649

JavaScript (ES6),  175  166165 bytes

m=>m.map(M=r=>(M|=v='0b'+r|0,m&=v||~0m&=v||m,v),m=~0).map(v=>v?(b=v+(v&-v))&b-1?3:v^m?2^v<M:1:0).join``.match(`^0*(1+${s=(g=m=>m?2+g(m&m-1):'')(m)}|${s}1+)0*$`)&&M*2&M/2&m^m

Try it online!Try it online!

m.map(M =                  // start with M zero'ish
  r =>                     // for each row r in m[]:
  ( M |= v = '0b' + r | 0, //   turn r into an integer v by parsing it as binary
                           //   and update M by doing M = M OR v
    m &= v || ~0m,           //   if v is not equal to 0, update m by doing m = m AND v
    v                      //   yield v as the actual value for the map()
  ),                       //
  m = ~0                   //   start with all bits set in m
)                          // end of map()
 input     | bin -> dec |  M |  m
-----------+------------+----+-----
 "0000000" |      0     |  0 | ~0
 "0100000" |     32     | 32 | 32
 "0100000" |     32     | 32 | 32
 "0111110" |     62     | 62 | 32
 "0000000" |      0     | 62 | 32
 input     | bin -> dec |  M |  m
-----------+------------+----+-----
 "0000000" |      0     |  0 | ~0
 "0100000" |     32     | 32 | 32
 "0100000" |     32     | 32 | 32
 "0111110" |     62     | 62 | 32
 "0000000" |      0     | 62 | 32

JavaScript (ES6),  175  166 bytes

m=>m.map(M=r=>(M|=v='0b'+r|0,m&=v||~0,v),m=~0).map(v=>v?(b=v+(v&-v))&b-1?3:v^m?2^v<M:1:0).join``.match(`^0*(1+${s=(g=m=>m?2+g(m&m-1):'')(m)}|${s}1+)0*$`)&&M*2&M/2&m^m

Try it online!

m.map(M =                  // start with M zero'ish
  r =>                     // for each row r in m[]:
  ( M |= v = '0b' + r | 0, //   turn r into an integer v by parsing it as binary
                           //   and update M by doing M = M OR v
    m &= v || ~0,          //   if v is not equal to 0, update m by doing m = m AND v
    v                      //   yield v as the actual value for the map()
  ),                       //
  m = ~0                   //   start with all bits set in m
)                          // end of map()
 input     | bin -> dec |  M |  m
-----------+------------+----+-----
 "0000000" |      0     |  0 | ~0
 "0100000" |     32     | 32 | 32
 "0100000" |     32     | 32 | 32
 "0111110" |     62     | 62 | 32
 "0000000" |      0     | 62 | 32

JavaScript (ES6), 165 bytes

m=>m.map(M=r=>(M|=v='0b'+r|0,m&=v||m,v),m=~0).map(v=>v?(b=v+(v&-v))&b-1?3:v^m?2^v<M:1:0).join``.match(`^0*(1+${s=(g=m=>m?2+g(m&m-1):'')(m)}|${s}1+)0*$`)&&M*2&M/2&m^m

Try it online!

m.map(M =                  // start with M zero'ish
  r =>                     // for each row r in m[]:
  ( M |= v = '0b' + r | 0, //   turn r into an integer v by parsing it as binary
                           //   and update M by doing M = M OR v
    m &= v || m,           //   if v is not equal to 0, update m by doing m = m AND v
    v                      //   yield v as the actual value for the map()
  ),                       //
  m = ~0                   //   start with all bits set in m
)                          // end of map()
 input     | bin -> dec |  M |  m
-----------+------------+----+-----
 "0000000" |      0     |  0 | ~0
 "0100000" |     32     | 32 | 32
 "0100000" |     32     | 32 | 32
 "0111110" |     62     | 62 | 32
 "0000000" |      0     | 62 | 32
updated test cases
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 649
added a note
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 649

ExampleIf the shape is valid:

  • \$m\$ is the pattern for the vertical leg
  • \$M\$ is the pattern for the horizontal leg
  • the list returned by map() contains only \$m\$, \$M\$ and optional \$0\$'s

Example:

 matrix       input     | bin -> dec |  M |  m
-------------------+------------+----+-----
 [ 0,0,0,0,0,0,0 ]"0000000" |      0     |  0 | ~0
 [ 0,1,0,0,0,0,0 ]"0100000" |     32     | 32 | 32
 [ 0,1,0,0,0,0,0 ]"0100000" |     32     | 32 | 32
 [ 0,1,1,1,1,1,0 ]"0111110" |     62     | 62 | 32
 [ 0,0,0,0,0,0,0 ]"0000000" |      0     | 62 | 32

Example:

 matrix            | bin -> dec |  M |  m
-------------------+------------+----+-----
 [ 0,0,0,0,0,0,0 ] |      0     |  0 | ~0
 [ 0,1,0,0,0,0,0 ] |     32     | 32 | 32
 [ 0,1,0,0,0,0,0 ] |     32     | 32 | 32
 [ 0,1,1,1,1,1,0 ] |     62     | 62 | 32
 [ 0,0,0,0,0,0,0 ] |      0     | 62 | 32

If the shape is valid:

  • \$m\$ is the pattern for the vertical leg
  • \$M\$ is the pattern for the horizontal leg
  • the list returned by map() contains only \$m\$, \$M\$ and optional \$0\$'s

Example:

 input     | bin -> dec |  M |  m
-----------+------------+----+-----
 "0000000" |      0     |  0 | ~0
 "0100000" |     32     | 32 | 32
 "0100000" |     32     | 32 | 32
 "0111110" |     62     | 62 | 32
 "0000000" |      0     | 62 | 32
saved 7 bytes
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 649
Loading
saved 1 byte
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 649
Loading
saved 1 byte
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 649
Loading
added an example for the 1st step
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 649
Loading
added a commented version
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 649
Loading
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 649
Loading