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. ↩︎
Post
Python 3, 463 400 343 bytes
-63 bytes thanks to trichoplax's suggestion to remove spaces
-57 bytes by simple conversion to base 36
where'dmyspacebarsgoinmypreviousedit?anyways,
lambda s:hex(sum(2**i*(c=='#')for i,c in enumerate(s)))[2:]in hex(int("am771a6n2yfu7ug75zes2q1su0f6gkn02oqfhz3lrnkgshfw089ql9jt5ij15gcgdkbqvvgs988w3jrz2rteixg1m9g6x9zjwwo6121ad1jae2vlb9n6exq73631tpgp0fjvemidcr1jm7vipjsxv7rsos2srbt5456mb79qqxiod0ay2tk927y060mqwiv8ggkn9565h93c2j3xrvd5jxcu4p2egw5qkh6rzcfrhsnqr2gn6i6vr5t3hj89xbgp0m51f",base=36))
Yet another interesting challenge foiled to brute force... (at least until someone comes up with a way to decision-problem this more efficiently...)
Anonymous lambda
function which takes string as input. Takes a power of 2 from the character indexes, indicating #
s with 1s and .
s/newlines with 0s. Sums up and manually checks a lookup table for all valid cube nets. Returns True
for cube nets and False
otherwise.
(i.e. if #
means include and .
/\n
mean exclude, 1st character has value 1, 2nd charcter has value 2, 3rd character has value 4, then values 8, 16, 32, and so on with all powers of 2 up to 240 inclusive)
0 comment threads