Comments on Net or not?
Parent
Net or not?
Given a hexomino, indicate whether it is a net of a cube.
Input
- A 6 by 6 grid containing exactly 6 filled squares.
- The 6 filled squares will be in a single edge connected set (a hexomino).
- The topmost row and leftmost column will never be empty (the hexomino will be as far up and left as it can go).
- The grid is represented as 6 newline separated strings of 6 characters, with
#
for a filled square and.
for an empty square.
Output
- One of 2 distinct values to indicate whether the hexomino can be folded to give a cube.
The hexominoes
A hexomino is an edge connected subset of the square tiling, composed of exactly 6 squares.
Up to rotation and reflection, there are 35 edge connected hexominoes, 11 of which are nets of a cube.
The 35 hexominoes[1]
The 11 nets of a cube[2]
Your code must also accept inputs that are rotations and reflections of these. There are a total of 216 hexominoes including all rotations by a multiple of 90 degrees and reflections, 64 of which are cube nets. The test cases include all of these.
Test cases
Cube nets
The 64 hexominoes that can be folded into a cube.
#.....
####..
#.....
......
......
......
.#....
.#....
.#....
###...
......
......
...#..
####..
...#..
......
......
......
###...
.#....
.#....
.#....
......
......
.##...
.#....
.#....
##....
......
......
...#..
####..
#.....
......
......
......
##....
.#....
.#....
.##...
......
......
#.....
####..
...#..
......
......
......
##....
.###..
.#....
......
......
......
#.....
###...
.#....
.#....
......
......
..#...
###...
.#....
.#....
......
......
.#....
.###..
##....
......
......
......
.#....
.#....
###...
#.....
......
......
..##..
###...
..#...
......
......
......
.#....
.#....
###...
..#...
......
......
..#...
###...
..##..
......
......
......
##....
.##...
..##..
......
......
......
#.....
##....
.##...
..#...
......
......
..##..
.##...
##....
......
......
......
..#...
.##...
##....
#.....
......
......
###...
..###.
......
......
......
......
..###.
###...
......
......
......
......
#.....
#.....
##....
.#....
.#....
......
.#....
.#....
##....
#.....
#.....
......
.#....
###...
.#....
.#....
......
......
.#....
.#....
###...
.#....
......
......
..#...
####..
..#...
......
......
......
.#....
####..
.#....
......
......
......
.#....
###...
..##..
......
......
......
..#...
.##...
##....
.#....
......
......
##....
.###..
..#...
......
......
......
.#....
.##...
##....
#.....
......
......
#.....
##....
.##...
.#....
......
......
..##..
###...
.#....
......
......
......
..#...
.###..
##....
......
......
......
.#....
##....
.##...
..#...
......
......
#.....
##....
.#....
.##...
......
......
..##..
###...
#.....
......
......
......
##....
.#....
.##...
..#...
......
......
.##...
.#....
##....
#.....
......
......
##....
.###..
...#..
......
......
......
#.....
###...
..##..
......
......
......
..#...
.##...
.#....
##....
......
......
...#..
.###..
##....
......
......
......
...#..
####..
..#...
......
......
......
.##...
##....
.#....
.#....
......
......
##....
.##...
.#....
.#....
......
......
.#....
####..
#.....
......
......
......
#.....
####..
.#....
......
......
......
.#....
.#....
##....
.##...
......
......
.#....
.#....
.##...
##....
......
......
..#...
####..
...#..
......
......
......
.#....
.##...
##....
.#....
......
......
.#....
####..
..#...
......
......
......
..#...
####..
.#....
......
......
......
.#....
##....
.##...
.#....
......
......
.#....
.##...
.#....
##....
......
......
.#....
##....
.#....
.##...
......
......
.##...
.#....
##....
.#....
......
......
##....
.#....
.##...
.#....
......
......
#.....
####..
..#...
......
......
......
..#...
####..
#.....
......
......
......
...#..
####..
.#....
......
......
......
.#....
####..
...#..
......
......
......
Not cube nets
The 152 hexominoes that cannot be folded into a cube.
..#...
#####.
......
......
......
......
#####.
..#...
......
......
......
......
.#....
.#....
##....
.#....
.#....
......
#.....
#.....
##....
#.....
#.....
......
.##...
###...
.#....
......
......
......
##....
###...
.#....
......
......
......
.#....
###...
##....
......
......
......
.#....
###...
.##...
......
......
......
##....
.####.
......
......
......
......
####..
...##.
......
......
......
......
#.....
##....
.#....
.#....
.#....
......
...##.
####..
......
......
......
......
.#....
.#....
.#....
##....
#.....
......
#.....
#.....
#.....
##....
.#....
......
.#....
##....
#.....
#.....
#.....
......
.####.
##....
......
......
......
......
.#....
##....
###...
......
......
......
#.....
###...
##....
......
......
......
###...
##....
.#....
......
......
......
##....
###...
#.....
......
......
......
###...
.##...
.#....
......
......
......
.##...
###...
..#...
......
......
......
..#...
###...
.##...
......
......
......
.#....
.##...
###...
......
......
......
###...
..#...
..##..
......
......
......
..#...
..#...
###...
#.....
......
......
..#...
###...
#.....
#.....
......
......
#.....
###...
..#...
..#...
......
......
.###..
.#....
##....
......
......
......
#.....
#.....
###...
..#...
......
......
..##..
..#...
###...
......
......
......
##....
.#....
.###..
......
......
......
####..
##....
......
......
......
......
.#....
.#....
##....
##....
......
......
..##..
####..
......
......
......
......
#.....
#.....
##....
##....
......
......
##....
##....
.#....
.#....
......
......
##....
####..
......
......
......
......
##....
##....
#.....
#.....
......
......
####..
..##..
......
......
......
......
####..
.#....
.#....
......
......
......
..#...
..#...
####..
......
......
......
..#...
..#...
###...
..#...
......
......
#.....
#.....
###...
#.....
......
......
#.....
###...
#.....
#.....
......
......
####..
..#...
..#...
......
......
......
.#....
.#....
####..
......
......
......
..#...
###...
..#...
..#...
......
......
####..
#.#...
......
......
......
......
.#....
##....
.#....
##....
......
......
#.#...
####..
......
......
......
......
#.....
##....
#.....
##....
......
......
##....
.#....
##....
.#....
......
......
.#.#..
####..
......
......
......
......
####..
.#.#..
......
......
......
......
##....
#.....
##....
#.....
......
......
...#..
...#..
####..
......
......
......
####..
...#..
...#..
......
......
......
..#...
..#...
..#...
###...
......
......
###...
..#...
..#...
..#...
......
......
###...
#.....
#.....
#.....
......
......
#.....
#.....
#.....
###...
......
......
#.....
#.....
####..
......
......
......
####..
#.....
#.....
......
......
......
.##...
##....
.##...
......
......
......
#.#...
###...
.#....
......
......
......
##....
.##...
##....
......
......
......
.#....
###...
#.#...
......
......
......
##....
##....
.##...
......
......
......
#.....
###...
.##...
......
......
......
..#...
###...
##....
......
......
......
.##...
###...
#.....
......
......
......
.##...
##....
##....
......
......
......
##....
.##...
.##...
......
......
......
##....
###...
..#...
......
......
......
.##...
.##...
##....
......
......
......
#.....
##....
###...
......
......
......
..#...
.##...
###...
......
......
......
###...
.##...
..#...
......
......
......
###...
##....
#.....
......
......
......
######
......
......
......
......
......
#.....
#.....
#.....
#.....
#.....
#.....
.###..
##....
.#....
......
......
......
.#....
###...
#.....
#.....
......
......
.#....
###...
..#...
..#...
......
......
..#...
..#...
###...
.#....
......
......
###...
..##..
..#...
......
......
......
.#....
##....
.###..
......
......
......
..#...
..##..
###...
......
......
......
#.....
#.....
###...
.#....
......
......
#.#...
###...
#.....
......
......
......
#.#...
###...
..#...
......
......
......
#.....
###...
#.#...
......
......
......
##....
.#....
###...
......
......
......
..#...
###...
#.#...
......
......
......
###...
.#....
##....
......
......
......
.##...
.#....
###...
......
......
......
###...
.#....
.##...
......
......
......
###...
###...
......
......
......
......
##....
##....
##....
......
......
......
#####.
....#.
......
......
......
......
....#.
#####.
......
......
......
......
#####.
#.....
......
......
......
......
##....
#.....
#.....
#.....
#.....
......
.#....
.#....
.#....
.#....
##....
......
#.....
#.....
#.....
#.....
##....
......
##....
.#....
.#....
.#....
.#....
......
#.....
#####.
......
......
......
......
#.....
#.#...
###...
......
......
......
###...
#.....
##....
......
......
......
###...
#.#...
#.....
......
......
......
###...
..#...
.##...
......
......
......
##....
#.....
###...
......
......
......
###...
#.#...
..#...
......
......
......
..#...
#.#...
###...
......
......
......
.##...
..#...
###...
......
......
......
###...
.###..
......
......
......
......
.#....
##....
##....
#.....
......
......
#.....
##....
##....
.#....
......
......
.###..
###...
......
......
......
......
##....
.##...
..#...
..#...
......
......
###...
..##..
...#..
......
......
......
..#...
..#...
.##...
##....
......
......
.##...
##....
#.....
#.....
......
......
.###..
##....
#.....
......
......
......
#.....
##....
.###..
......
......
......
#.....
#.....
##....
.##...
......
......
...#..
..##..
###...
......
......
......
.##...
####..
......
......
......
......
#.....
##....
##....
#.....
......
......
.#....
##....
##....
.#....
......
......
####..
.##...
......
......
......
......
##....
.#....
##....
#.....
......
......
##....
#.....
##....
.#....
......
......
##.#..
.###..
......
......
......
......
.###..
##.#..
......
......
......
......
#.##..
###...
......
......
......
......
.#....
##....
#.....
##....
......
......
###...
#.##..
......
......
......
......
#.....
##....
.#....
##....
......
......
.#....
##....
.#....
.#....
.#....
......
...#..
#####.
......
......
......
......
#.....
#.....
#.....
##....
#.....
......
.#....
#####.
......
......
......
......
.#....
.#....
.#....
##....
.#....
......
#####.
...#..
......
......
......
......
#.....
##....
#.....
#.....
#.....
......
#####.
.#....
......
......
......
......
#..#..
####..
......
......
......
......
##....
.#....
.#....
##....
......
......
####..
#..#..
......
......
......
......
##....
#.....
#.....
##....
......
......
Scoring
This is a code golf challenge. Your score is the number of bytes in your code. Lowest score for each language wins.
Explanations are optional, but I'm more likely to upvote answers that have one.
-
Thanks to The 35 hexominoes Wikimedia page. ↩︎
-
Thanks to The 11 nets of a cube Wikimedia page. ↩︎
[Python 3], 463 400 343 338 by …
5d ago
Python 3 + PYTHONHASHSEED=764, …
1d ago
Rust, 325 bytes A closure (an …
4d ago
Post
Python 3 + PYTHONHASHSEED=764, 193+18=211 bytes
This doesn't work with Python's default settings, because for security reasons hash
gives different results for the same input on different runs. It needs 18 extra bytes to define an environment variable to make Python give consistent output, to allow hardcoding the long string:
PYTHONHASHSEED=764
The code is then a lambda (anonymous) function which converts the input string to the last 3 characters of the hexadecimal form of its hash, and then checks if this is present in the concatenation of 3 character strings for all of the nets (which is stored as base 36 and converted to hex for the check).
lambda s:hex(hash(s))[-3:]in hex(int("5h9fh4xkwqqqgfqz410wog4mjsotxldb6dyfalqrcukexb2b8dni5xoyy19urmbgn8pgfjkqk42clxpgmbtlods6i25sbbw5lxn8fij4zpi0wpp7kzvylxeogi2i0wmg83pxjm57dm0igt4j5b057",36))
I initially tried with the environment variable set to 1, and this required the last 4 characters of the hex hash in order to avoid getting false positives for the non-net hexominoes. I wondered if changing the seed might give a collection of hashes where just the last 3 characters would be sufficient to avoid false positives.
To find out, I wrote the following Python file to give no output unless all test cases pass, in which case it would output the value of the environment variable:
a.py
nets="""#.....
####..
#.....
......
......
......
.#....
.#....
.#....
###...
......
......
...#..
####..
...#..
......
......
......
###...
.#....
.#....
.#....
......
......
.##...
.#....
.#....
##....
......
......
...#..
####..
#.....
......
......
......
##....
.#....
.#....
.##...
......
......
#.....
####..
...#..
......
......
......
##....
.###..
.#....
......
......
......
#.....
###...
.#....
.#....
......
......
..#...
###...
.#....
.#....
......
......
.#....
.###..
##....
......
......
......
.#....
.#....
###...
#.....
......
......
..##..
###...
..#...
......
......
......
.#....
.#....
###...
..#...
......
......
..#...
###...
..##..
......
......
......
##....
.##...
..##..
......
......
......
#.....
##....
.##...
..#...
......
......
..##..
.##...
##....
......
......
......
..#...
.##...
##....
#.....
......
......
###...
..###.
......
......
......
......
..###.
###...
......
......
......
......
#.....
#.....
##....
.#....
.#....
......
.#....
.#....
##....
#.....
#.....
......
.#....
###...
.#....
.#....
......
......
.#....
.#....
###...
.#....
......
......
..#...
####..
..#...
......
......
......
.#....
####..
.#....
......
......
......
.#....
###...
..##..
......
......
......
..#...
.##...
##....
.#....
......
......
##....
.###..
..#...
......
......
......
.#....
.##...
##....
#.....
......
......
#.....
##....
.##...
.#....
......
......
..##..
###...
.#....
......
......
......
..#...
.###..
##....
......
......
......
.#....
##....
.##...
..#...
......
......
#.....
##....
.#....
.##...
......
......
..##..
###...
#.....
......
......
......
##....
.#....
.##...
..#...
......
......
.##...
.#....
##....
#.....
......
......
##....
.###..
...#..
......
......
......
#.....
###...
..##..
......
......
......
..#...
.##...
.#....
##....
......
......
...#..
.###..
##....
......
......
......
...#..
####..
..#...
......
......
......
.##...
##....
.#....
.#....
......
......
##....
.##...
.#....
.#....
......
......
.#....
####..
#.....
......
......
......
#.....
####..
.#....
......
......
......
.#....
.#....
##....
.##...
......
......
.#....
.#....
.##...
##....
......
......
..#...
####..
...#..
......
......
......
.#....
.##...
##....
.#....
......
......
.#....
####..
..#...
......
......
......
..#...
####..
.#....
......
......
......
.#....
##....
.##...
.#....
......
......
.#....
.##...
.#....
##....
......
......
.#....
##....
.#....
.##...
......
......
.##...
.#....
##....
.#....
......
......
##....
.#....
.##...
.#....
......
......
#.....
####..
..#...
......
......
......
..#...
####..
#.....
......
......
......
...#..
####..
.#....
......
......
......
.#....
####..
...#..
......
......
......"""
not_nets="""..#...
#####.
......
......
......
......
#####.
..#...
......
......
......
......
.#....
.#....
##....
.#....
.#....
......
#.....
#.....
##....
#.....
#.....
......
.##...
###...
.#....
......
......
......
##....
###...
.#....
......
......
......
.#....
###...
##....
......
......
......
.#....
###...
.##...
......
......
......
##....
.####.
......
......
......
......
####..
...##.
......
......
......
......
#.....
##....
.#....
.#....
.#....
......
...##.
####..
......
......
......
......
.#....
.#....
.#....
##....
#.....
......
#.....
#.....
#.....
##....
.#....
......
.#....
##....
#.....
#.....
#.....
......
.####.
##....
......
......
......
......
.#....
##....
###...
......
......
......
#.....
###...
##....
......
......
......
###...
##....
.#....
......
......
......
##....
###...
#.....
......
......
......
###...
.##...
.#....
......
......
......
.##...
###...
..#...
......
......
......
..#...
###...
.##...
......
......
......
.#....
.##...
###...
......
......
......
###...
..#...
..##..
......
......
......
..#...
..#...
###...
#.....
......
......
..#...
###...
#.....
#.....
......
......
#.....
###...
..#...
..#...
......
......
.###..
.#....
##....
......
......
......
#.....
#.....
###...
..#...
......
......
..##..
..#...
###...
......
......
......
##....
.#....
.###..
......
......
......
####..
##....
......
......
......
......
.#....
.#....
##....
##....
......
......
..##..
####..
......
......
......
......
#.....
#.....
##....
##....
......
......
##....
##....
.#....
.#....
......
......
##....
####..
......
......
......
......
##....
##....
#.....
#.....
......
......
####..
..##..
......
......
......
......
####..
.#....
.#....
......
......
......
..#...
..#...
####..
......
......
......
..#...
..#...
###...
..#...
......
......
#.....
#.....
###...
#.....
......
......
#.....
###...
#.....
#.....
......
......
####..
..#...
..#...
......
......
......
.#....
.#....
####..
......
......
......
..#...
###...
..#...
..#...
......
......
####..
#.#...
......
......
......
......
.#....
##....
.#....
##....
......
......
#.#...
####..
......
......
......
......
#.....
##....
#.....
##....
......
......
##....
.#....
##....
.#....
......
......
.#.#..
####..
......
......
......
......
####..
.#.#..
......
......
......
......
##....
#.....
##....
#.....
......
......
...#..
...#..
####..
......
......
......
####..
...#..
...#..
......
......
......
..#...
..#...
..#...
###...
......
......
###...
..#...
..#...
..#...
......
......
###...
#.....
#.....
#.....
......
......
#.....
#.....
#.....
###...
......
......
#.....
#.....
####..
......
......
......
####..
#.....
#.....
......
......
......
.##...
##....
.##...
......
......
......
#.#...
###...
.#....
......
......
......
##....
.##...
##....
......
......
......
.#....
###...
#.#...
......
......
......
##....
##....
.##...
......
......
......
#.....
###...
.##...
......
......
......
..#...
###...
##....
......
......
......
.##...
###...
#.....
......
......
......
.##...
##....
##....
......
......
......
##....
.##...
.##...
......
......
......
##....
###...
..#...
......
......
......
.##...
.##...
##....
......
......
......
#.....
##....
###...
......
......
......
..#...
.##...
###...
......
......
......
###...
.##...
..#...
......
......
......
###...
##....
#.....
......
......
......
######
......
......
......
......
......
#.....
#.....
#.....
#.....
#.....
#.....
.###..
##....
.#....
......
......
......
.#....
###...
#.....
#.....
......
......
.#....
###...
..#...
..#...
......
......
..#...
..#...
###...
.#....
......
......
###...
..##..
..#...
......
......
......
.#....
##....
.###..
......
......
......
..#...
..##..
###...
......
......
......
#.....
#.....
###...
.#....
......
......
#.#...
###...
#.....
......
......
......
#.#...
###...
..#...
......
......
......
#.....
###...
#.#...
......
......
......
##....
.#....
###...
......
......
......
..#...
###...
#.#...
......
......
......
###...
.#....
##....
......
......
......
.##...
.#....
###...
......
......
......
###...
.#....
.##...
......
......
......
###...
###...
......
......
......
......
##....
##....
##....
......
......
......
#####.
....#.
......
......
......
......
....#.
#####.
......
......
......
......
#####.
#.....
......
......
......
......
##....
#.....
#.....
#.....
#.....
......
.#....
.#....
.#....
.#....
##....
......
#.....
#.....
#.....
#.....
##....
......
##....
.#....
.#....
.#....
.#....
......
#.....
#####.
......
......
......
......
#.....
#.#...
###...
......
......
......
###...
#.....
##....
......
......
......
###...
#.#...
#.....
......
......
......
###...
..#...
.##...
......
......
......
##....
#.....
###...
......
......
......
###...
#.#...
..#...
......
......
......
..#...
#.#...
###...
......
......
......
.##...
..#...
###...
......
......
......
###...
.###..
......
......
......
......
.#....
##....
##....
#.....
......
......
#.....
##....
##....
.#....
......
......
.###..
###...
......
......
......
......
##....
.##...
..#...
..#...
......
......
###...
..##..
...#..
......
......
......
..#...
..#...
.##...
##....
......
......
.##...
##....
#.....
#.....
......
......
.###..
##....
#.....
......
......
......
#.....
##....
.###..
......
......
......
#.....
#.....
##....
.##...
......
......
...#..
..##..
###...
......
......
......
.##...
####..
......
......
......
......
#.....
##....
##....
#.....
......
......
.#....
##....
##....
.#....
......
......
####..
.##...
......
......
......
......
##....
.#....
##....
#.....
......
......
##....
#.....
##....
.#....
......
......
##.#..
.###..
......
......
......
......
.###..
##.#..
......
......
......
......
#.##..
###...
......
......
......
......
.#....
##....
#.....
##....
......
......
###...
#.##..
......
......
......
......
#.....
##....
.#....
##....
......
......
.#....
##....
.#....
.#....
.#....
......
...#..
#####.
......
......
......
......
#.....
#.....
#.....
##....
#.....
......
.#....
#####.
......
......
......
......
.#....
.#....
.#....
##....
.#....
......
#####.
...#..
......
......
......
......
#.....
##....
#.....
#.....
#.....
......
#####.
.#....
......
......
......
......
#..#..
####..
......
......
......
......
##....
.#....
.#....
##....
......
......
####..
#..#..
......
......
......
......
##....
#.....
#.....
##....
......
......"""
pattern="".join(hex(hash(x))[-3:] for x in nets.split("\n\n"))
f=lambda s:hex(hash(s))[-3:]in pattern
for net in nets.split("\n\n"):
if not f(net):
exit()
for not_net in not_nets.split("\n\n"):
if f(not_net):
exit()
import os
print(os.environ['PYTHONHASHSEED'])
I then ran this with ascending values for the environment variable using Bash:
for ((i=0;i<1000;i++));do PYTHONHASHSEED=$i python a.py;done
The smallest working value this found was 764.
Testing
Testing this online is difficult because it only works with the environment variable set.
Locally, you can save the a.py
file and then run it with:
PYTHONHASHSEED=764 python a.py
If this outputs 764
then all of the test cases have passed. If any fail it will output nothing.
0 comment threads