A Perfect Level

Name:  “The Secret Pyramid” (or more simply, “The Pyramid”).  

Gallery:  the 90s theme set

Original version of image:  90+91

What Is A Perfect Level?  

My definition: 

A level with a distinctive centralized pattern that none of the major lines significantly deviate from.  It helps when the pattern looks like something, though it kills the level completely if another level I have seen looks too much like it.  

Note that perfect doesn’t necessarily mean best.  Many of my favorite levels feature complex, multi-faceted patterns that are far from being perfect.  

The Level That Defined Perfect

Multiple versions of this level available here and here.  

The “P” clearly had a lot to do with why I called it Perfect. 

In the 9 galleries between 80×80 (the “P”) and 90+91, (the “Pyramid”), none of the levels that I saw fit my definition (the fact that 8 of the galleries are 100×100 or bigger had something to do with this).  However, there were a few: 

Repeats

This much bigger and in some ways more impressive pyramid was one of my favorite levels from the 101×99 gallery.   Then I saw this image while working on the 111×109 gallery:

Despite being arguably a more perfect version of the first (the colors suck because I didn’t try to find anything better), this repeat not only ruined the first level, my opinion of any level with a pyramid temporarily went down by quite a bit.  

Even though I wouldn’t quite call either of them a perfect level on their own because the main pattern takes up less than half the board and isn’t centralized – repeats can and have spoiled other seemingly perfect levels.  

Other Pyramids

The pyramid is a relatively uncommon pattern but I have seen numerous other examples.  Here is one of the first next to “The Secret Pyramid”:

The 1st level is from the 75×75 gallery and one of the better complex patterns I’ve seen despite (or because of) the relatively small board size. 

At 91×91, The Pyramid is almost 50% bigger, but it doesn’t look it:  the pattern in the 75×75 level makes the level look bigger, while the pattern in The Pyramid makes it look smaller. 

What Makes this Pyramid Different? 

  1. It’s not really a pyramid. 
  2. The house border.  
  3. It’s centralized.
  4. It’s the only distinct pattern in the level. 

Redefining Perfect

The main reason I think The Pyramid is more perfect than The P is the small mini-sector in the bottom right of The P:

While this area isn’t bad – it is separate from the P and might even disqualify the level from meeting my above definition.  

The area shows one of the main reasons perfect levels are so rare:  A distinctive pattern at the center of a level is usually going to require at least one area like this in order to fill a square or rectangular board.  

An Optical Illusion

The left version is the original flipped horizontally – everything else is exactly the same between the two images.  

I don’t know why, but for whatever reason, the slight imbalances in the house area make the right side look more balanced, while having completely the opposite effect for the left side.  

The Secret Pyramid

Alternate names:  “The House”, “The Igloo”,  “Shelter”

I went with The Secret Pyramid because in my mind, I had already used “The House” and “The Igloo” for earlier levels.  

The name refers to the pyramid-like shape in the center of the house-like shape.  The secret part will be revealed later. 

Why is it Perfect? 

The pyramid is relatively small – why doesn’t everything outside the pyramid disqualify it from being perfect? 

There are two reasons: 

  1. The rest of the board essentially forms a frame for the pyramid
  2. The  cyan line defines the shape for the entire board which the rest of the lines follow. 

The cyan line not only forms the central pattern, but it also answers the question:  given the house shaped area, how can we fill the rest of the board without creating a separate distinctive pattern elsewhere? 

The Three Layers

The cyan line distinctly separates the board into three layers (or sectors).  

  1. The black outer layer, which I call a frame.  There are 5 lines covering 4060 cells in this area (not counting the cyan line). 
  2. The blue middle layer.  (39 lines, 2619 cells)
  3. The purple house shaped layer. (17 lines, 1060 cells)

The Passageways

The cyan line forms a narrow passageway between each of the three layers.  It also creates a much longer and wider passageway within the middle layer that connects the two narrow passageways.  

The outer passageway: 

The dark rose line from the outer layer enters the passageway, but doesn’t quite make it into the middle layer and blocks all other lines from entering the passageway. 

The inner passageway: 

This time, the cyan line completely blocks the pass.  The violet and dark green lines both arrive at dead ends.  

The middle passageway:

You would think I would be a little better at drawing stuff in photoshop considering I have a website dedicated to computer art, but I’m really not.

The effect is that the pyramid feels very far away from the outer frame.  The pyramid being further hidden inside the house is another reason why I call the level “The Secret Pyramid.”

Even The Crap Is Perfect

Crap:  short lines that fill space but don’t contribute to the pattern (I call them “filler” lines).  

Crap zones:  An area of the board where there are many of these lines.  

Large crap zones often spoil an otherwise perfectly good level for me.  My program uses a separate darker color palette for short lines to effectively hide them. 

The Trap

I like to call this area “the trap”, because it is trapezoidal, and I imagine that the many dots inside it once sought glory in a quest to find the pyramid.  

The area contained by the blue and purple lines is definitely a crap zone.  The 11 lines that fill the 33 cells are all just 3 cells long -the minimum line length according to the rules I provide my level generator (a 2 cell line would just be 2 dots next to each other). 

The Rules for the Level Generator

  1. Every cell of the grid must be filled by a line that is at least 3 cells long.
  2. The zig-zag rule:  Lines cannot have unnecessary bends just to fill space.  One way to define this is that a single line can’t fill an entire 2×2 square of cells.  For example: 

the yellow line violates the 2nd rule when it tries to go to the “X” by covering all 4 of the cells within the green square.  The line could have gone from the bottom right of the square to the X without moving to the bottom left/top left cells, thus making this an unnecessary bend.  

Perfect Areas

A contained area of the board is perfect if it is filled by the minimum number of lines possible according to the above rules.  

Examples:  

Any perfectly square area (above:  15×15, 225 cells) can be filled with just 2 lines by following the spiral pattern. 

The not coincidentally house-shaped area is just 97 cells, yet requires at least 5 lines to fill according to the rules.  The above demonstrates one of the many different ways to do this.  

The shape of the area is often more important than the size of the area when determining the minimum number of lines required to fill it.  

The Trap Is Perfect 

Although it is impossible to fill the 33-cell area with more than 11 lines without violating the minimum line length rule, it is also impossible to fill it with fewer than 11 lines while adhering to both rules:

The yellow dot is at a dead-end – a line must begin here and continue to the cell directly above it.  

The line is only 2 cells at this point, so it must continue to either the red ? or purple ?

The only cell the line can go from either ? is the cell with the green X.  

However, if the line enters the X, the other ? becomes isolated and can’t be filled by another line.  So the line must continue from the X to the other ?, but this would violate the zig-zag rule.  

Thus the line must end at exactly 3 cells in length and not enter the green X.  

The cycle continues for each successive line within the trapezoid – where no line can exceed 3 cells without breaking either of the rules.  

Unusual Within the Unusual

The 11 connected 3 cell lines (C3CLs) seemed unusual to me, so I ran a script to see if it had happened before.  The results: 

C3CLs # Levels Pct*
14 1 0.05%
13 1 0.10%
11 3 0.26%
10 1 0.31%
8 3 0.46%
7 5 0.72%
6 6 1.03%
5 31 2.62%
4 147 10.17%
3 478 34.74%
2 1183 95.53%
1 87 100.00%

*- cumulative percent

Of the 1946 levels my program checked – every level I have looked at an image for since 45×45 – only 2 levels had a larger sector of 3 cell lines.  The winner, with 14 connected 3 cell lines: 

The pink outlines the area for this level in the 101×99 set.  At the time, my solution to hide the junk lines was to get rid of them before imaging – though the dots remain mainly to show that lines ones existed.

These areas are not common:  only 1% of the levels had an area of 6 or more connected 3 cell lines.  

Levels with these areas tend to have a lot of lines:  

C3CLs # Lev Avg Lines Min
7+ 13 176.1 105
4-6 147 155 67
1-3 1748 101.5 23
The Pyramid (11) 1 62 62

 

  • The Secret Pyramid has just 62 total lines – about 18% of the lines are in this area that covers less than 0.4% of the board.  
  • Of the 130 other levels with 62 or fewer total lines, none of them had more than 3 connected 3 cell lines. 
  • The other 51 lines average 162 cells, about 5 times the size of the entire trapezoid.  
    • Coincidentally, there are 51 other levels with 5+ 3CLs.  Not counting these lines, the average line length doesn’t exceed 100 cells for any of these levels. 

What About the Other Crap?

The 11 3-cell lines inside The Trap aren’t the only filler lines in the level.  A bunch of them are located inside the pyramid: 

Due to the multiple sets of “steps” (jagged lines that approximate diagonals), the pyramid shape tends to result in a lot of short lines to fill according to the rules.  This pyramid is one of the best that I’ve seen for a few reasons: 

  1. The major lines (the central green line and anything longer than it) cover most of the area. 
  2. There are no filler lines between the red and cyan lines, where the pyramid flattens into a house.  
  3. I can’t find an easy way to reduce the line count either by combining any of the short lines or extending any of the longer lines. 

To test it’s relative perfectness, I had my program generate 1000 levels following the shape of the cyan line inside the pyramid. 

This is the best it could do in terms of minimizing the line count: 

The 15 lines are just 2 less than the 17 in The Pyramid, though the lines shift the focus to the bottom right instead of the center.  

Less than 2% of the levels had 17 lines or less, with the average being 40 lines, which can look like this:

or this: 

among the many different ways to draw 40 lines within the shape.  

This diversion ended up leading to the page:  A Pyramid Diversion.

The Longest Short Line

For the purpose of the remainder of this article, I will use the longest line inside the pyramid shorter than the green line (47 cells) as the cutoff point for defining what makes a line “short.”   

The straight blue line bordering the green line is that line, and it happens to be 11 cells long.  

Interestingly, there are exactly 11 short lines inside the pyramid.

The Rest of the Board

While there are no short lines in the outer layer, there are a handful scattered throughout the middle layer that are not in the trapezoid.  One particular area beneath the pyramid stands out because it is easily “fixable”: 

The area isn’t perfect because the 4 completely visible lines here can be replaced with just 2 straight lines.  Further, all 4 lines could be eliminated by extending the purple and blue lines from the right side of the yellow rectangle to the left side.  

Within this area, 3 of the 4 lines qualify as short – at 12 cells, the dark orange line just misses the cutoff. 

Additionally, there are 7 other 3 cell lines scattered throughout the middle layer but not part of the trapezoid: 

 

There is just one other short line not accounted for (hint, it connects two of the lines in the circles above) .  This brings the total number of short lines in the middle layer but not inside the trapezoid to: 11.

How Close To Perfect

The table shows the progress I’ve made so far in an attempt to reduce the number of lines in the 3 sectors: 

Layer The Pyramid Optimized
Outer 5 5
Middle 39 35
House 17 15

By visual inspection I was unable to reduce the line count in the house layer, but able to reduce the line count by 4 in the middle layer.  Since my program was able to reduce the line count in the house layer to 15, I gave it a chance to do better for the other two layers.   

This resulted in the page:  A Pyramid Diversion

While the outer layer cannot be improved, my program was able to reduce the line count to 31 lines in the middle layer.  However, it was in this level that I found an improvement: 

The far from perfect house area has 33 lines – but the middle layer has just 32 lines.  

It is possible to reduce the line count even further by altering lines in the following two areas: 

The 3 lines inside the rectangles can be eliminated – though it requires splitting another line in two for the 2nd area.   The net reduction of two lines makes the minimum line count in the middle sector 30 lines.  

Here’s the table again:

Layer The Pyramid Minimum
Outer 5 5
Middle 39 30
House 17 15
Total 61 50

Given the cyan line only – it takes a minimum of 50 lines to fill the entire board.  

Yet again, the Secret Pyramid manages to be perfectly imperfect – dodging perfection by a total of:

11 lines 

A recap of all the numbers: 

  • 3 layers, 3 passageways, 3 sides to a pyramid.  
  • An area of 11 connected 3 cell lines cover 33 cells.
  • There are 11 short lines inside the pyramid – with the longest line being 11 cells long.
  • There are 11 additional lines 11 cells or fewer outside of these two areas. 
  • That makes separate areas with 11 short lines, and a total of 33 lines with 11 or fewer cells in the level.
  • The level has 11 more lines than necessary to fill the area defined by the cyan line only.  
  • A computer program generated all of the lines exactly as you see them (not counting the color of the lines) in the image above – starting with a blank grid of 91×91 cells. 
  • God Exists.  Q.E.D.