Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 141 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

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.

Try it online! Try it online!

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 -10 0
4 80 10 0ignored (-d)
5 101 00 1
6 12-1 -11 1
7 140 11 1
811

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.

Try it online!

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.

Try it online!

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
811
added 31 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

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.

Try it online!

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\$
00-1-1
121-1
240-1
36-10
4810
51001
612-11
71411

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.

Try it online!

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.

Try it online!

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\$
00-1-1
121-1
240-1
36-10
4810
51001
612-11
71411
added 31 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

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.

Try it online! Try it online!

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.

Try it online!

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.

Try it online!

Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293
Loading

AltStyle によって変換されたページ (->オリジナル) /