Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Net​​ or​​ not?

+1
−0

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 35 hexominoes

The 11 nets of a cube[2]

The 11 nets of a cube

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.


  1. Thanks to The 35 hexominoes Wikimedia page. ↩︎

  2. Thanks to The 11 nets of a cube Wikimedia page. ↩︎

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

3 answers

You are accessing this answer with a direct link, so it's being shown above all other answers regardless of its score. You can return to the normal view.

+0
−0

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.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

Should this be Python 3 or a separate language? (1 comment)
+1
−0

Python 3, 463 400 343 338 bytes

-63 bytes thanks to trichoplax's suggestion to remove spaces
-57 bytes by simple conversion to base 36
-5 bytes by removing base= (seriously, how did I miss this, thanks trichoplax)

lambda s:hex(sum(2**i*(c=='#')for i,c in enumerate(s)))[2:]in hex(int("aM771A6N2Yfu7ug75zes2q1Su0f6gkn02oqfhz3lrnkgshfw089ql9jt5ij15gcgdkbqvvgs988w3jrz2rteixg1M9g6x9zjwwO6121ad1jae2vlb9n6exq73631Tpgp0fjvemidcr1jm7vipjSxv7rsos2srbt5456mb79qqxiod0ay2tk927y060mqwiv8ggkn9565h93c2j3xrvd5jxcu4p2egw5qkh6rzcfrhsnqr2gn6i6vr5t3hj89xbgp0m51f",36))

Try it online!

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)

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

3 comment threads

Probable improvements (3 comments)
Omitting the spaces (4 comments)
Base 36 (4 comments)
+0
−0

Rust, 325 bytes

A closure (anonymous function) returning true for a net, or false otherwise.

|s|"83e423a313e423e8c1a383e213e823e143e223e443e441ec83a313e233a831acc1e223e233a421ec83e81fcc1e111ecc1e413e133a243e183e172743a343e8".contains(&format!("{:x}",(0..2).map(|c|(0..36).map(|m|{let n=if c<1{m}else{6*(m%6)+m/6};1<<m*(s.as_bytes().iter().filter(|&&x|x>10).nth(n)==Some(&35))as usize}).sum::<u64>()+2).min().unwrap()))

Testing

I used the following code to verify all test cases pass while adjusting the function. You can confirm they pass online, on Rust Playground.

const NETS: &str = "#.....
####..
#.....
......
......
......

.#....
.#....
.#....
###...
......
......

...#..
####..
...#..
......
......
......

###...
.#....
.#....
.#....
......
......

.##...
.#....
.#....
##....
......
......

...#..
####..
#.....
......
......
......

##....
.#....
.#....
.##...
......
......

#.....
####..
...#..
......
......
......

##....
.###..
.#....
......
......
......

#.....
###...
.#....
.#....
......
......

..#...
###...
.#....
.#....
......
......

.#....
.###..
##....
......
......
......

.#....
.#....
###...
#.....
......
......

..##..
###...
..#...
......
......
......

.#....
.#....
###...
..#...
......
......

..#...
###...
..##..
......
......
......

##....
.##...
..##..
......
......
......

#.....
##....
.##...
..#...
......
......

..##..
.##...
##....
......
......
......

..#...
.##...
##....
#.....
......
......

###...
..###.
......
......
......
......

..###.
###...
......
......
......
......

#.....
#.....
##....
.#....
.#....
......

.#....
.#....
##....
#.....
#.....
......

.#....
###...
.#....
.#....
......
......

.#....
.#....
###...
.#....
......
......

..#...
####..
..#...
......
......
......

.#....
####..
.#....
......
......
......

.#....
###...
..##..
......
......
......

..#...
.##...
##....
.#....
......
......

##....
.###..
..#...
......
......
......

.#....
.##...
##....
#.....
......
......

#.....
##....
.##...
.#....
......
......

..##..
###...
.#....
......
......
......

..#...
.###..
##....
......
......
......

.#....
##....
.##...
..#...
......
......

#.....
##....
.#....
.##...
......
......

..##..
###...
#.....
......
......
......

##....
.#....
.##...
..#...
......
......

.##...
.#....
##....
#.....
......
......

##....
.###..
...#..
......
......
......

#.....
###...
..##..
......
......
......

..#...
.##...
.#....
##....
......
......

...#..
.###..
##....
......
......
......

...#..
####..
..#...
......
......
......

.##...
##....
.#....
.#....
......
......

##....
.##...
.#....
.#....
......
......

.#....
####..
#.....
......
......
......

#.....
####..
.#....
......
......
......

.#....
.#....
##....
.##...
......
......

.#....
.#....
.##...
##....
......
......

..#...
####..
...#..
......
......
......

.#....
.##...
##....
.#....
......
......

.#....
####..
..#...
......
......
......

..#...
####..
.#....
......
......
......

.#....
##....
.##...
.#....
......
......

.#....
.##...
.#....
##....
......
......

.#....
##....
.#....
.##...
......
......

.##...
.#....
##....
.#....
......
......

##....
.#....
.##...
.#....
......
......

#.....
####..
..#...
......
......
......

..#...
####..
#.....
......
......
......

...#..
####..
.#....
......
......
......

.#....
####..
...#..
......
......
......";

const NOT_NETS: &str = "..#...
#####.
......
......
......
......

#####.
..#...
......
......
......
......

.#....
.#....
##....
.#....
.#....
......

#.....
#.....
##....
#.....
#.....
......

.##...
###...
.#....
......
......
......

##....
###...
.#....
......
......
......

.#....
###...
##....
......
......
......

.#....
###...
.##...
......
......
......

##....
.####.
......
......
......
......

####..
...##.
......
......
......
......

#.....
##....
.#....
.#....
.#....
......

...##.
####..
......
......
......
......

.#....
.#....
.#....
##....
#.....
......

#.....
#.....
#.....
##....
.#....
......

.#....
##....
#.....
#.....
#.....
......

.####.
##....
......
......
......
......

.#....
##....
###...
......
......
......

#.....
###...
##....
......
......
......

###...
##....
.#....
......
......
......

##....
###...
#.....
......
......
......

###...
.##...
.#....
......
......
......

.##...
###...
..#...
......
......
......

..#...
###...
.##...
......
......
......

.#....
.##...
###...
......
......
......

###...
..#...
..##..
......
......
......

..#...
..#...
###...
#.....
......
......

..#...
###...
#.....
#.....
......
......

#.....
###...
..#...
..#...
......
......

.###..
.#....
##....
......
......
......

#.....
#.....
###...
..#...
......
......

..##..
..#...
###...
......
......
......

##....
.#....
.###..
......
......
......

####..
##....
......
......
......
......

.#....
.#....
##....
##....
......
......

..##..
####..
......
......
......
......

#.....
#.....
##....
##....
......
......

##....
##....
.#....
.#....
......
......

##....
####..
......
......
......
......

##....
##....
#.....
#.....
......
......

####..
..##..
......
......
......
......

####..
.#....
.#....
......
......
......

..#...
..#...
####..
......
......
......

..#...
..#...
###...
..#...
......
......

#.....
#.....
###...
#.....
......
......

#.....
###...
#.....
#.....
......
......

####..
..#...
..#...
......
......
......

.#....
.#....
####..
......
......
......

..#...
###...
..#...
..#...
......
......

####..
#.#...
......
......
......
......

.#....
##....
.#....
##....
......
......

#.#...
####..
......
......
......
......

#.....
##....
#.....
##....
......
......

##....
.#....
##....
.#....
......
......

.#.#..
####..
......
......
......
......

####..
.#.#..
......
......
......
......

##....
#.....
##....
#.....
......
......

...#..
...#..
####..
......
......
......

####..
...#..
...#..
......
......
......

..#...
..#...
..#...
###...
......
......

###...
..#...
..#...
..#...
......
......

###...
#.....
#.....
#.....
......
......

#.....
#.....
#.....
###...
......
......

#.....
#.....
####..
......
......
......

####..
#.....
#.....
......
......
......

.##...
##....
.##...
......
......
......

#.#...
###...
.#....
......
......
......

##....
.##...
##....
......
......
......

.#....
###...
#.#...
......
......
......

##....
##....
.##...
......
......
......

#.....
###...
.##...
......
......
......

..#...
###...
##....
......
......
......

.##...
###...
#.....
......
......
......

.##...
##....
##....
......
......
......

##....
.##...
.##...
......
......
......

##....
###...
..#...
......
......
......

.##...
.##...
##....
......
......
......

#.....
##....
###...
......
......
......

..#...
.##...
###...
......
......
......

###...
.##...
..#...
......
......
......

###...
##....
#.....
......
......
......

######
......
......
......
......
......

#.....
#.....
#.....
#.....
#.....
#.....

.###..
##....
.#....
......
......
......

.#....
###...
#.....
#.....
......
......

.#....
###...
..#...
..#...
......
......

..#...
..#...
###...
.#....
......
......

###...
..##..
..#...
......
......
......

.#....
##....
.###..
......
......
......

..#...
..##..
###...
......
......
......

#.....
#.....
###...
.#....
......
......

#.#...
###...
#.....
......
......
......

#.#...
###...
..#...
......
......
......

#.....
###...
#.#...
......
......
......

##....
.#....
###...
......
......
......

..#...
###...
#.#...
......
......
......

###...
.#....
##....
......
......
......

.##...
.#....
###...
......
......
......

###...
.#....
.##...
......
......
......

###...
###...
......
......
......
......

##....
##....
##....
......
......
......

#####.
....#.
......
......
......
......

....#.
#####.
......
......
......
......

#####.
#.....
......
......
......
......

##....
#.....
#.....
#.....
#.....
......

.#....
.#....
.#....
.#....
##....
......

#.....
#.....
#.....
#.....
##....
......

##....
.#....
.#....
.#....
.#....
......

#.....
#####.
......
......
......
......

#.....
#.#...
###...
......
......
......

###...
#.....
##....
......
......
......

###...
#.#...
#.....
......
......
......

###...
..#...
.##...
......
......
......

##....
#.....
###...
......
......
......

###...
#.#...
..#...
......
......
......

..#...
#.#...
###...
......
......
......

.##...
..#...
###...
......
......
......

###...
.###..
......
......
......
......

.#....
##....
##....
#.....
......
......

#.....
##....
##....
.#....
......
......

.###..
###...
......
......
......
......

##....
.##...
..#...
..#...
......
......

###...
..##..
...#..
......
......
......

..#...
..#...
.##...
##....
......
......

.##...
##....
#.....
#.....
......
......

.###..
##....
#.....
......
......
......

#.....
##....
.###..
......
......
......

#.....
#.....
##....
.##...
......
......

...#..
..##..
###...
......
......
......

.##...
####..
......
......
......
......

#.....
##....
##....
#.....
......
......

.#....
##....
##....
.#....
......
......

####..
.##...
......
......
......
......

##....
.#....
##....
#.....
......
......

##....
#.....
##....
.#....
......
......

##.#..
.###..
......
......
......
......

.###..
##.#..
......
......
......
......

#.##..
###...
......
......
......
......

.#....
##....
#.....
##....
......
......

###...
#.##..
......
......
......
......

#.....
##....
.#....
##....
......
......

.#....
##....
.#....
.#....
.#....
......

...#..
#####.
......
......
......
......

#.....
#.....
#.....
##....
#.....
......

.#....
#####.
......
......
......
......

.#....
.#....
.#....
##....
.#....
......

#####.
...#..
......
......
......
......

#.....
##....
#.....
#.....
#.....
......

#####.
.#....
......
......
......
......

#..#..
####..
......
......
......
......

##....
.#....
.#....
##....
......
......

####..
#..#..
......
......
......
......

##....
#.....
#.....
##....
......
......";

fn main() {
    println!(
        "{}",
        match NETS.split("\n\n").all(
|s|"83e423a313e423e8c1a383e213e823e143e223e443e441ec83a313e233a831acc1e223e233a421ec83e81fcc1e111ecc1e413e133a243e183e172743a343e8".contains(&format!("{:x}",(0..2).map(|c|(0..36).map(|m|{let n=if c>0{m}else{6*(m%6)+m/6};1<<m*(s.as_bytes().iter().filter(|&&x|x>10).nth(n)==Some(&35))as usize}).sum::<u64>()+2).min().unwrap()))        
        ) {
            true => "Net test cases pass.",
            _ => "Net test cases fail.",
        }
    );
    println!(
        "{}",
        match !NOT_NETS.split("\n\n").any(
|s|"83e423a313e423e8c1a383e213e823e143e223e443e441ec83a313e233a831acc1e223e233a421ec83e81fcc1e111ecc1e413e133a243e183e172743a343e8".contains(&format!("{:x}",(0..2).map(|c|(0..36).map(|m|{let n=if c>0{m}else{6*(m%6)+m/6};1<<m*(s.as_bytes().iter().filter(|&&x|x>10).nth(n)==Some(&35))as usize}).sum::<u64>()+2).min().unwrap()))
        ) {
            true => "Not net test cases pass.",
            _ => "Not net test cases fail.",
        }
    );
}

Explanation

|s|{ // Closure (anonymous function) taking input s
  "83e423a313e423e8c1a383e213e823e143e223e443e441ec83a313e233a831acc1e223e233a421ec83e81fcc1e111ecc1e413e133a243e183e172743a343e8"
    .contains( // True if the string above contains what follows
      &format!( // The format macro helps convert to String
        "{:x}", // :x means the value will be shown as hex
        (0..2) // For the range from 0 to 1 (excluding 2)
          .map( // Apply the following function to each
            |c|{
              (0..36) // For 0 to 35
                .map(
                  |m|{
                    let n=if c<1{
                      m // Untransformed first time
                    }else{
                      6*(m%6)+m/6 // Transposed second time
                    };
                    1<<m*( // The mth power of 2 multiplied by
                      s // The string input
                        .as_bytes()
                        .iter()
                        .filter(|&&x|x>10) // Omitting newlines
                        .nth(n)==Some(&35) // True if nth character is #
                    )as usize // Change false to 0, true to 1
                  })
                .sum::<u64>() // Sum the powers of 2
              +2 // Modify so that none of the non-nets are substrings
            }
          )
          .min() // Take smallest of untransformed & transposed versions
          .unwrap(), // as min returns Option (None if empty iterator)
      )
    )
};

Treat as binary

Uses the approach from hydroxyl-radical's Python answer of treating each # as a 1 in the binary representation of an integer, and checking if the integer corresponding to the input string is present in a string of all the integers corresponding to nets.

Convert to hex

The string is shortened by converting to hexadecimal (unlike Python, Rust doesn't have a built in way of converting to a higher base than 16).

Omit newlines and spaces

The string is also shortened by filtering out the newlines from the input, rather than treating them as 0s, giving slightly smaller integers. Frustratingly, this makes some of the non-net integers substrings of some of the net integers in hexadecimal. The +2 to prevent this happening eats into the bytes saved, but does conveniently mean that there is no longer a need for spaces between the hex strings, because now no non-net hex string is a substring, even with the net hex strings concatenated.

Discard transposed forms

The input string is converted to a hex string twice, once as is, and once after transposing it (reflecting it in its leading diagonal). The smallest of the two resulting hex strings is used, so the larger one is no longer needed in the long string, reducing it by significantly better than half.

I did consider also rotating to give all 8 forms of the input string (4 rotations by 90 degrees, reflected to give 8 forms). This would mean only the canonical 11 nets would need to be included in the long string, much reducing it. However, rotating would require also shifting the input up and left (after rotating) to avoid an empty top row or left column (which would give a different hex string). I don't think I can do this in few enough bytes to make the saving in string length worthwhile, but I'm mentioning it in case it's effective in another language.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »