Python 3, 151150 bytes
...or 149 in Python 2 150 by changing // to /.
-1 Thanks to att - subtract d when considering the cell itself to avoid needing to ignore it.)
lambda p,e=enumerate:[{sum(b[i+2*n%3b[i+n%3-1][j+2*n1][j+n//53-1]for n in range(89))-d for b,a in zip(p,p[1:])for i,r in e(b)for j,s in e(r)if s^d<a[i][j]}for d in(0,1)]
An unnamed function that accepts the pattern, p, and returns the minimal B and S as a list of two sets.
The eight deltas to neighbours are calculated from n in range(89) as:
| \$n\$$$n$$ | \2ドルn\$$$\delta x=n \pmod 3 - 1$$ | \$\delta x=2n \pmod 3 - 1\$ | $$\delta y=\lfloor \frac{n}{3} \rfloor - 1$$ | \$\delta y=\lfloor \frac{2n}{5} \rfloor - 1\$ | comment |
|---|---|---|---|---|---|
| 0 | 0-1 | -1 | -1 | -1 | |
| 1 | 20 | 1 | -1 | -1 | |
| 2 | 41 | 0 | -1 | -1 | |
| 3 | 6-1 | -1 | 0 | 0 | |
| 4 | 80 | 1 | 0 | 0 | ignored (-d) |
| 5 | 101 | 0 | 0 | 1 | |
| 6 | 12-1 | -1 | 1 | 1 | |
| 7 | 140 | 1 | 1 | 1 | |
| 8 | 1 | 1 |
Python 3, 151 bytes
...or Python 2 150 by changing // to /.
lambda p,e=enumerate:[{sum(b[i+2*n%3-1][j+2*n//5-1]for n in range(8))for b,a in zip(p,p[1:])for i,r in e(b)for j,s in e(r)if s^d<a[i][j]}for d in(0,1)]
An unnamed function that accepts the pattern, p, and returns the minimal B and S as a list of two sets.
The eight deltas to neighbours are calculated from n in range(8) as:
| \$n\$ | \2ドルn\$ | \$\delta x=2n \pmod 3 - 1\$ | \$\delta y=\lfloor \frac{2n}{5} \rfloor - 1\$ |
|---|---|---|---|
| 0 | 0 | -1 | -1 |
| 1 | 2 | 1 | -1 |
| 2 | 4 | 0 | -1 |
| 3 | 6 | -1 | 0 |
| 4 | 8 | 1 | 0 |
| 5 | 10 | 0 | 1 |
| 6 | 12 | -1 | 1 |
| 7 | 14 | 1 | 1 |
Python 3, 150 bytes
...or 149 in Python 2 by changing // to /.
-1 Thanks to att - subtract d when considering the cell itself to avoid needing to ignore it.)
lambda p,e=enumerate:[{sum(b[i+n%3-1][j+n//3-1]for n in range(9))-d for b,a in zip(p,p[1:])for i,r in e(b)for j,s in e(r)if s^d<a[i][j]}for d in(0,1)]
An unnamed function that accepts the pattern, p, and returns the minimal B and S as a list of two sets.
The deltas to neighbours are calculated from n in range(9) as:
| $$n$$ | $$\delta x=n \pmod 3 - 1$$ | $$\delta y=\lfloor \frac{n}{3} \rfloor - 1$$ | comment |
|---|---|---|---|
| 0 | -1 | -1 | |
| 1 | 0 | -1 | |
| 2 | 1 | -1 | |
| 3 | -1 | 0 | |
| 4 | 0 | 0 | ignored (-d) |
| 5 | 1 | 0 | |
| 6 | -1 | 1 | |
| 7 | 0 | 1 | |
| 8 | 1 | 1 |
Python 3, 151 bytes
...or Python 2 150 by changing // to /.
lambda p,e=enumerate:[{sum(b[i+2*n%3-1][j+2*n//5-1]for n in range(8))for b,a in zip(p,p[1:])for i,r in e(b)for j,s in e(r)if s^d<a[i][j]}for d in(0,1)]
An unnamed function that accepts the pattern, p, and returns the minimal B and S as a list of two sets.
The eight deltas to neighbours are calculated from n in range(8) as:
| \$n\$ | \2ドルn\$ | \$\delta x=2n \pmod 3 - 1\$ | \$\delta y=\lfloor \frac{2n}{5} \rfloor - 1\$ |
|---|---|---|---|
| 0 | 0 | -1 | -1 |
| 1 | 2 | 1 | -1 |
| 2 | 4 | 0 | -1 |
| 3 | 6 | -1 | 0 |
| 4 | 8 | 1 | 0 |
| 5 | 10 | 0 | 1 |
| 6 | 12 | -1 | 1 |
| 7 | 14 | 1 | 1 |
Python 3, 151 bytes
...or Python 2 150 by changing // to /.
lambda p,e=enumerate:[{sum(b[i+2*n%3-1][j+2*n//5-1]for n in range(8))for b,a in zip(p,p[1:])for i,r in e(b)for j,s in e(r)if s^d<a[i][j]}for d in(0,1)]
An unnamed function that accepts the pattern, p, and returns the minimal B and S as a list of two sets.
Python 3, 151 bytes
...or Python 2 150 by changing // to /.
lambda p,e=enumerate:[{sum(b[i+2*n%3-1][j+2*n//5-1]for n in range(8))for b,a in zip(p,p[1:])for i,r in e(b)for j,s in e(r)if s^d<a[i][j]}for d in(0,1)]
An unnamed function that accepts the pattern, p, and returns the minimal B and S as a list of two sets.
The eight deltas to neighbours are calculated from n in range(8) as:
| \$n\$ | \2ドルn\$ | \$\delta x=2n \pmod 3 - 1\$ | \$\delta y=\lfloor \frac{2n}{5} \rfloor - 1\$ |
|---|---|---|---|
| 0 | 0 | -1 | -1 |
| 1 | 2 | 1 | -1 |
| 2 | 4 | 0 | -1 |
| 3 | 6 | -1 | 0 |
| 4 | 8 | 1 | 0 |
| 5 | 10 | 0 | 1 |
| 6 | 12 | -1 | 1 |
| 7 | 14 | 1 | 1 |
Python 3 (or Python 2), 153151 bytes
...or Python 2 150 by changing // to /.
lambda p,e=enumerate:[{sum(b[i+n%3b[i+2*n%3-1][j+2*n%7%31][j+2*n//5-1]for n in range(8,16))for b,a in zip(p,p[1:])for i,r in e(b)for j,s in e(r)if s^d<a[i][j]}for d in(0,1)]
An unnamed function that accepts the pattern, p, and returns the minimal B and S as a list of two sets.
Python 3 (or Python 2), 153 bytes
lambda p,e=enumerate:[{sum(b[i+n%3-1][j+2*n%7%3-1]for n in range(8,16))for b,a in zip(p,p[1:])for i,r in e(b)for j,s in e(r)if s^d<a[i][j]}for d in(0,1)]
An unnamed function that accepts the pattern, p, and returns the minimal B and S as a list of two sets.
Python 3, 151 bytes
...or Python 2 150 by changing // to /.
lambda p,e=enumerate:[{sum(b[i+2*n%3-1][j+2*n//5-1]for n in range(8))for b,a in zip(p,p[1:])for i,r in e(b)for j,s in e(r)if s^d<a[i][j]}for d in(0,1)]
An unnamed function that accepts the pattern, p, and returns the minimal B and S as a list of two sets.