title: Exact Cover Puzzle

text:
# Question
Title: Exact Cover Puzzle
# CHALLENGE

Given a set of grouped letters, arrange them onto the board so that they cover the area entirely.

## Board Representation (a.k.a. the SHIP DECK)

* The board is a 6x6 grid.
* There will always be 36 total squares.
* Columns are marked A-F.
* Rows are marked 1-6.

Example:

```
    A   B   C   D   E   F
  +---+---+---+---+---+---+
1 :   :   :   :   :   :   :
  +---+---+---+---+---+---+
2 :   :   :   :   :   :   :
  +---+---+---+---+---+---+
3 :   :   :   :   :   :   :
  +---+---+---+---+---+---+
4 :   :   :   :   :   :   :
  +---+---+---+---+---+---+
5 :   :   :   :   :   :   :
  +---+---+---+---+---+---+
6 :   :   :   :   :   :   :
  +---+---+---+---+---+---+

```

# INPUT (a.k.a. the CRATES)

* A multiline string containing the set of grouped letters.
* Crates are made from the groups of identical letters.
* The crates are IMMUTABLE, meaning they can't be rotated or flipped.
* The starting point for each crate is on the top left (should be taken into account when moving a crate onto the deck).
* From the top left point of a crate, the following identical squares can only be to the right or below.
* Any letter can be used to represent a crate. The crates always start at letter `[a]` and move up the alphabet.
* Crates are labeled by their letter (i.e. crate A, crate B, etc.)
* The number of crates can vary (it isn't always 10, despite the examples given).
* There are 24 characters separating each block of crates per line. (start of \[a\] to start of \[b\] separated by 24 characters, etc.)

Example:

```
[a][a][a]               [b]                     [c][c]
      [a]               [b][b][b]                  [c]
      [a]               [b][b]

[d]                     [e]                     [f][f][f][f][f]
[d][d]                  [e]
[d][d]                  [e]
                        [e]
                        [e][e]

[g]                     [h]                     [i]
[g]                                             [i]
                                                [i]

```

# OUTPUT

It is required that you print out a series of commands that place the crates in positions on the deck so that it is covered completely (no empty spaces).

The command format is like so:

`HAUL <crate> TO <column> <row>`

i.e. HAUL E TO A 1

For clarification, there will always be a solution for the input given.

# TEST CASES \<-- Click for more.

## Input

```
[a][a][a]               [b]                     [c][c][c]
   [a][a]               [b]
   [a]                  [b][b]
                        [b][b]

[d]                     [e]                     [f]
[d]                                             [f]
[d]                                             [f]
[d]
[d]

[g][g]                  [h]                     [i]
                                                [i][i]
                                                   [i]
                                                   [i][i]

[j][j][j]

```

## Output

```
HAUL I TO A 1
HAUL B TO A 3
HAUL A TO B 1
HAUL J TO D 6
HAUL D TO F 1
HAUL F TO E 1
HAUL C TO C 5
HAUL G TO D 4
HAUL E TO D 3
HAUL H TO C 6

```

Result:

```
    A   B   C   D   E   F
  +---+---+---+---+---+---+
1 : i : a : a : a : f : d :
  +---+---+---+---+---+---+
2 : i : i : a : a : f : d :
  +---+---+---+---+---+---+
3 : b : i : a : e : f : d :
  +---+---+---+---+---+---+
4 : b : i : i : g : g : d :
  +---+---+---+---+---+---+
5 : b : b : c : c : c : d :
  +---+---+---+---+---+---+
6 : b : b : h : j : j : j :
  +---+---+---+---+---+---+

```

# SCORING

This is so the shortest answer in characters wins.

# Answer
# Python 3.6, ~~435~~ ~~437~~ ~~385~~ 331 bytes

Call `F()` with the crate string.

```
def R(b,d,i=0):
 if not d:return 1
 (k,x),*d=d
 while x:
  if x&b<1and R(b|x,d):print(f'HAUL {k.upper()} TO {i%7+65:c} {i//7+1}');return 1
  i+=1;x>>=1
def F(t,d={},e={}):
 r=c=0
 for a in t:
  if'`'<a<'{':e[a]=x,y=e.get(a,(r,c));d[a]=d.get(a,0)+(1<<(48-(r-x)*7-(c-y)//3))
  elif'\n'==a:r+=1;c=-1
  c+=1
 R(4432676798719,d.items())

```

Managed to golf it a lot more:

1. Parse the crate string directly instead of using the `re` library.
2. Used setdefault to save the first coordinate of a set of crates, so that the bitmask can be created when parsing the crate string. Eliminating a for loop.

Prior version
```
import re
def R(b,d,i=0):
 if not d:return 1
 (k,x),*d=d
 while x:
  if not x&b and R(b|x,d):print(f'HAUL {k.upper()} TO {i%7+65:c} {i//7+1}');return 1
  i+=1;x>>=1
def F(t,d={},n=0):
 for r in t.split('\n'):
  for m in re.finditer(r'(.)]',r):d[m[1]]=d.get(m[1],[])+[(n,m.start())]
  n+=1
 R(4432676798719,[(k,sum(1<<(48-(r-v[0][0])*7-(c-v[0][1])//3)for r,c in v))for k,v in d.items()])

```

Restructured the code to remove redundant loops.

1. Previous code built a list of all positions of a crate in `F()` and then iterated over the list in `R()`. New code creates one position of a crate in `F()` and `R()` tries all possible positions.
2. In previous code, `R()` collected a possible solution in `a` and `F()` then iterated over the returned solution. In new code, `R()` prints the HAUL commands directly

Previous version
```
import re
def R(b,d,a=[]):
 if not d:yield a
 for x in d[0]:
  if not x&b:yield from R(b|x,d[1:],a+[x])
def F(t,d={},n=0):
 for r in t.split('\n'):
  for m in re.finditer(r'(.)]',r):d[m[1]]=d.get(m[1],[])+[(n,m.start())]
  n+=1
 for k,j in enumerate(next(R(4432676798719,[[sum(1<<(48-(r-v[0][0])*7-(c-v[0][1])//3)for r,c in v)>>i for i in range(48)]for k,v in d.items()]))):x=51-len(bin(j));print(f'HAUL {k+65:c} TO {x%7+65:c} {x//7+1}')

```

### Explanation

The basic idea is to represent the ship's deck and the crates as bit maps. By using bitmaps, moving a crate becomes a shift of its bitmap and checking for overlap between crates becomes a bit-wise AND and test for zero.

Ungolfed code:

```
import re

def F(crate_string):                                                                 #  3
  coords = {}
  row_no = 0

  for row in crate_string.split('\n'):                                               #  7

    for match_obj in re.finditer('(.)]', row):                                       #  9

      crate_name = match_obj[1]                                                      # 11
      col_no = match_obj.start()                                                     # 12
      coords[crate_name] = coords.get(crate_name, []) + [(row_no, col_no)]           # 13

    row_no += 1

  normed = {k:[(r-v[0][0], (c-v[0][1])//3) for r,c in v] for k,v in coords.items()}  # 17
  bitmaps = [(k,sum(1<<(48 - r*7 - c) for r,c in v)) for k,v in normed.items()]      # 18

  R(4432676798719, bitmaps)                                                          # 20

def R(used, bitmaps):                                                                # 22
  if not bitmaps:                                                                    # 23
    return True                                                                      # 24
  shift = 0                                                                          # 25
  (crate_name, crate_bitmap),*bitmaps = bitmaps                                      # 26

  while crate_bitmap:                                                                # 28
    if not used & crate_bitmap:                                                      # 29
      if R(used | crate_bitmap, bitmaps):                                            # 30
        print(f'HAUL {crate_name.upper()} TO {shift%7 + 65:c} {shift//7 + 1}')       # 31
        return True                                                                  # 32

    shift += 1                                                                       # 34
    crate_bitmap >>= 1                                                               # 35

  return False                                                                       # 37

```

`F()` parses the crate definition string and builds the bit maps. A regex searches (line 9) each line of the crate definition string for crates (a letter followed by a '\]'). When a match is found, the corresponding (row,col) is added to a dictionary keyed by the letter (lines 11-13). For the example crate definition string given in the problem:

```
coords = {'a': [(0, 5), (0, 8), (0, 11), (1, 5), (1, 8), (1, 11)],
          'b': [(0, 29), (1, 29), (2, 29)],
               ... }

```

The coordinates of each crate are normalized (line 17), so that each crate starts at (0,0) and each block is one unit wide (instead of 3 a la '\[a\]').

```
normed = {'a': [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2)],
          'b': [(0, 0), (1, 0), (2, 0)],
               ... }

```

A bitmap is then created for each crate based on the normalized coordinates (line 18).

The deck is treated as a 7 x 7 grid. Column 'G' and row 7 are used to detect when a shape extends off the board. A bitmap has a 1 if the crates would occupy the corresponding square on the deck. Bits 48 to bit to 42 correspond to squares A1 to A7, bits 41 to 35 correspond to squares B1 to B7, and so on.

```
bitmaps = [('a', 0b1110000_1110000_0000000_0000000_0000000_0000000_0000000),
           ('b', 0b1000000_1000000_1000000_0000000_0000000_0000000_0000000),
           ...
           ]

```

`R(used, bitmaps)` then uses the bitmaps to recursively search for crate placements that don't try to put two crates in the same square. `used` is a bitmask indicating which squares can't be used because they are already occupied by a crate or because they are off the board (i.e., column G and row 7). `bitmaps` is a list of crates that still need to be placed.

The base case for the recursion is when there are no more crates left to place, i.e., `bitmaps` is empty (line 23). In this case True is returned to indicate a solution has been found.

Otherwise, a crate name and its bitmap are popped off the list of bitmaps (line 26). While the crate bitmap is not empty (line 28), check if the current crate placement, represented by the crate bitmap, conflicts with any previously placed crates. At line 29, `not used & crate_bitmap` is False if `used` and `crate_bitmap` both have a 1 in the same bit position, indicating a conflict. If there is not a conflict, `R()` is called recursively (line 30) to try and place the remaining crates.

If the recursive call to `R()` returns True, it means that a solution has been found and that the current placement of the crates is part of that solution. So the corresponding command to move the crates is printed and True is propagated up the recursive calls (lines 31-32).

When created in `F()`, each crate bitmap represents the deck squares that would be occupied by the crates if they are placed at position A1. Shifting a bitmap one bit to the right corresponds to moving the crates to position A2. A seven bit right shift corresponds to moving the crates to B1, etc. For example, the following bitmaps represent crates 'a' at various positions:

```
0b1110000_1110000_0000000_0000000_0000000_0000000_0000000  represent crates 'a' at A1
0b0111000_0111000_0000000_0000000_0000000_0000000_0000000  represent crates 'a' at A2
0b0011100_0011100_0000000_0000000_0000000_0000000_0000000  represent crates 'a' at A3
                                 ...
0b0000000_1110000_1110000_0000000_0000000_0000000_0000000  represent crates 'a' at B1
                                 ...

```

If a possible placement of crates doesn't work because it conflicts with a previously placed crate (line 30) or because there is not a valid placement of the remaining crates (line 31). The crates are moved to a different position by shifting the bitmask right one bit (line 35). `Shift` keeps track of how many places the bit map has been shifted, which corresponds to the current position of the crates.

If the bitmap is empty (zero), it indicates that all possible placement have been tried. False is returned (line 37) to indicate failure so that a call to `R()` earlier in the recursion will try another placement for its crates.

To ensure that the crates don't extend off the side of the deck, bits corresponding to column G and row 7 are set in `used` for the initial call to `R()` (line 20).

`4432676798719` is the empty deck corresponding to `0b0000001000000100000010000001000000100000011111111`
> 5 votes

# Answer
# Python 2, 864 bytes

* Thanks to Stephen for finding a bug.
* The string parsing could be golfed significantly, as the input format is stricter than what it can handle.

```
def V(C,S=0,D=-1,J=0,H=[],E=enumerate,R=range,r=str.replace,s=str.split,e="!"):
 if[]<C*0:
	J=0;N=[J]*26;K=[]
	for c in s(r(r(r(C,"[",""),"]",""),"   ","*"),2*"\n"):
	 c=[list(_)for _ in s(c,"\n")]
	 for x,_ in E(c[0]):
		if all(c[y][x]<">"for y,_ in E(c)):
		 for y,_ in E(c):c[y][x]=e
	 for j,y in E(c):
		y="".join(y)
		while"!!"in y:y=r(y,2*e,e)
		c[j]=s(y,e)
	 K+=[],[],[],[];J+=4
	 for y in c:
		while""in y:y.remove("")
		for j,x in E(y):K[j+J-4]+=x,
	for k in K:
	 if all(k)and k:N[ord(k[0][0])-97]=[[x>"*"for x in y]for y in k]
	while 0in N:N.remove(0)
	C=N
 if[]>S:S=[0]*36
 if-~D>0:
	Y=J/6;j=0
	for y in C[D]:
	 X=J%6
	 for x in y:
		if x:
		 if X>5or Y>5or S[X+Y*6]:return
		 S[X+Y*6]=x
		X+=1
	 Y+=1
 if~-len(C)==D:
	if 0in S:return
	for h in H[1:]+[J]:print"HAUL %c TO %c %d"%(65+j,65+h%6,h/6+1);j+=1
	j/0
 for j in R(36):V(C,S[:],-~D,j,H*(D>=0)+[J])

```

Try it online!

# Explanation

A lot of bytes are used to parse the two-dimensional crates inputted through a single string. Crates are represented as a nested list of boolean values.
After the crates are parsed, the function considers all possible positions of all crates. To do so, it iteratively calls itself. When it finds an impossible position (if the crate would be placed outside the deck or on top of another crate), it kills the current recursion tree branch to improve performance.
When it sees that a certain combination of placements resulted in a completely covered deck, it prints the recorded crate placement history and globally exits by attempting a hopeless division. The printed haul instructions are even sorted alphabetically.

---

# Python 2, 812 bytes

```
def f(C,M=[],d=0,R=range,E=enumerate,L=len):
 if C*0=="":
	N=[0]*26;K=[];J=0
	r=str.replace
	for c in r(r(r(C,"[",""),"]",""),"   ","*").split("\n\n"):
	 c=[list(_)for _ in c.split("\n")]
	 for x in R(L(c[0])):
		if all(c[y][x]=="*"for y in R(L(c))):
		 for y in R(L(c)):c[y][x]="!"
	 for j,y in E(c):
		y="".join(y)
		while"!!"in y:y=r(y,"!!","!")
		c[j]=y.split("!")
	 for _ in"_"*L(c):K+=[],
	 for y in c:
		for j,x in E(y):K[j+J]+=x,
	 J+=L(c)
	for k in K:
	 if all(k)and k:N[ord(k[0][0])-97]=[[x!="*"for x in y]for y in k]
	while 0in N:N.remove(0)
	C=N
 if d==L(C):
	j=0;S=[j]*36
	for c,k in E(C):
	 Y=M[c]/6
	 for y in k:
		X=M[c]%6
		for x in y:
		 if X<6>Y:S[X+Y*6]|=x
		 X+=1
		Y+=1
	if 0in S:return
	for m in M:print"HAUL %c TO %c %d"%(65+j,65+m%6,1+m/6);j+=1
	j/0
 for j in R(36):f(C,M*(d>=0)+[j],d+1)

```

Try it online!

# Explanation

The crate string is parsed and transformed into a listed nest of booleans representing each crate.
An iterative function generates all possible lists of length equal to the amount of crates given containing the integers `0 <= x < 36` (all possible ship deck positions). Every list is interpreted as an instruction to position all crates and tested. If the tested instruction list results in a deck with no empty spaces, the instruction list has to be valid and gets printed.
Being extremely inefficient, I did not test it on the provided test case, though on scenarios with fewer crates (see the TIO link). Because the algorithm searches through *every* possible arrangement, it tries to look at `36**10 = 3.656e15` of them. Yet *in theory* it should still work.
> 5 votes

# Answer
# JavaScript, 366

```
k=>(x=y=0,C={},B=[...k].map((c,p)=>(c<' '?(x=0,++y):c<'a'?++x:(c=C[c=parseInt(c,36)]||(C[c]=[[],x,y]))[0].push((y-c[2])*7+(x++-c[1])/3),p<8|p>48|p%7<1)),S=[],R=i=>!C[i]||B.some((v,p)=>v?0:C[i][0].every(q=>B[q+=p]?0:B[q]=i)&&R(i+1,S[i-10]=p)||!C[i][0].map(q=>B[q+=p]==i?B[q]=0:0)),R(10),S.map((v,c)=>`HAUL ${(c+10).toString(36)} TO ${(v%7+9).toString(36)} ${v/7|0}`))

```

Note: this function can parse a more compact input, as it does not care about spacing by 24 chars, and holes in crates are allowed.

I think it could be golfed a little more, but now it's short and not too much slow, so I like it as is

*Less golfed*

```
k=>(
  // input parsing
  var x = 0, y = 0, // current position
      C = []; // crates
  [...k].forEach( c =>
  c < ' '
  ? (x = 0, ++y) // found a newline, increment y, reset x
  : c < 'a'
    ? ++x // not a letter, increment x
    : (  // found a letter, update the crate
        c = parseInt(c,36), // letter to number (10..35)
        c = C[c], // current crate in c
        c || (C[c]=[[], x, y]), // if new crate, initialize it setting base position
        c[0].push((y - c[2])*7 + (x-c[1])/3) // add current position
        ++x // increment x also
      )
  );
  var B = [...Array(7*8)] // empty board. in golfed code I reuse k to build B. k is big enough
  B = B.map( (_, p) => // set borders
     p < 8 | p > 48 | p%7<1
  )
  var S = [] // output steps

  // recursive function to fill board
  var R = i =>
    ! C[i] // if crate at position i exists (else, we have found a solution and return true)
    ||
    B.some( (v,p) => // try to put crate at each position in B
      v // current cell is used already ?
      ? 0 // used, return false
      : C[i][0].every( q => // try this position, must place every part
          B[q+=p] // current position in B is used ?
          ? 0 // used, stop, return false
          : B[q]=i // mark as used
        )
        && R(i+1,S[i-10]=p) // ok for current crate, try next, mark step
        || // else, fail for current crate, clear position marked
        !C[i][0].map(q =>
          B[q+=p]==i ? B[q]=0:0 // clear if it was set to 'i'
        )
    ),
  R(10) // start recursive fill at position 10 (that is 'a')
  // it returns true if ok, but we don't care as we are assured a solution exists
  // now just format output
  return S.map((v,c)=>`HAUL ${(c+10).toString(36)} TO ${(v%7+9).toString(36)} ${v/7|0}`)
)

```

**Test cases** lots of them

```
var F=
k=>(x=y=0,C={},B=[...k].map((c,p)=>(c<' '?(x=0,++y):c<'a'?++x:(c=C[c=parseInt(c,36)]||(C[c]=[[],x,y]))[0].push((y-c[2])*7+(x++-c[1])/3),p<8|p>48|p%7<1)),S=[],R=i=>!C[i]||B.some((v,p)=>v?0:C[i][0].every(q=>B[q+=p]?0:B[q]=i)&&R(i+1,S[i-10]=p)||!C[i][0].map(q=>B[q+=p]==i?B[q]=0:0)),R(10),
// Just for debug: return the fill in addition to the steps
[B.slice(7,50).map((c,i)=>i%7?c.toString(36):'\n'),
S.map((v,c)=>`HAUL ${(c+10).toString(36)} TO ${(v%7+9).toString(36)} ${v/7|0}`)])

var Test = [
 "[a][a][a]               [b]                     [c][c]\n      [a]               [b][b][b]                  [c]\n      [a]               [b][b]\n\n[d]                     [e]                     [f][f][f][f][f]\n[d][d]                  [e]\n[d][d]                  [e]\n                        [e]\n                        [e][e]\n\n[g]                     [h]                     [i]\n[g]                                             [i]\n                                                [i]"
,"[a][a][a]               [b]                     [c][c][c]\n   [a][a]               [b]\n   [a]                  [b][b]\n                        [b][b]\n\n[d]                     [e]                     [f]\n[d]                                             [f]\n[d]                                             [f]\n[d]\n[d]\n\n[g][g]                  [h]                     [i]\n                                                [i][i]\n                                                   [i]\n                                                   [i][i]\n\n[j][j][j]"
,"[a]                     [b][b][b]               [c]\n[a]                           [b]\n[d]                     [e]                     [f][f]\n[d]                     [e]\n[d][d][d]\n[g]                     [h]                     [i]\n[g]                     [h][h][h]               [i]\n                              [h]               [i][i]\n                              [h]                  [i]\n                                                   [i]\n[j]                     [k][k][k]\n[j]\n[j]"
,"[a][a][a][a]            [b][b][b]               [c]\n                              [b]               [c]\n                              [b]               [c][c]\n                                                   [c][c]\n[d]                     [e]                     [f]\n[d]                                             [f][f][f]\n[g]                     [h]                     [i][i]\n                        [h][h][h]               [i][i]\n                           [h][h]\n[j]\n[j]\n[j]"
,"[a]                     [b]                     [c][c]\n[a]                     [b]\n[a]\n[d][d]                  [e]                     [f][f][f]\n[d][d][d]\n[g]                     [h]                     [i]\n                        [h]\n                        [h]\n                        [h][h]\n                           [h]\n[j]                     [k][k][k]\n[j][j]                     [k][k]\n[j][j][j]                     [k]"
,"[a]                     [b][b][b]               [c]\n[a]                                             [c]\n                                                [c]\n[d][d]                  [e]                     [f]\n[d][d][d][d]            [e]                     [f]\n                        [e][e][e][e]            [f]\n[g]                     [h][h][h]               [i][i][i]\n                              [h]               [i][i][i]\n[j][j]"
,"[a]                     [b]                     [c][c][c]\n                        [b]\n[d]                     [e][e]                  [f][f]\n[d][d][d]                                       [f][f]\n[d][d]\n[g]                     [h][h][h]               [i]\n[g]                           [h]               [i][i]\n[g]                           [h]               [i][i]\n[g]\n[g]\n[j]\n[j]\n[j]"
,"[a][a]                  [b]                     [c]\n   [a][a]               [b][b]                  [c]\n                        [b][b][b]               [c]\n[d]                     [e][e][e]               [f][f][f]\n[d]                     [e][e][e]\n[g][g]                  [h]                     [i]\n                                                [i]\n                                                [i][i]\n[j][j]\n   [j]\n   [j]\n   [j]"
,"[a][a]                  [b]                     [c]\n[a][a]                  [b][b]                  [c]\n                        [b][b][b]\n[d][d]                  [e]                     [f][f][f]\n[g]                     [h]                     [i][i]\n[g]                     [h]                        [i]\n[g]                     [h]\n[g]\n[g][g]\n[j]\n[j]\n[j]\n[j][j]\n   [j]"
,"[a]                     [b]                     [c][c][c][c][c]\n                        [b]\n                        [b][b][b]\n                              [b]\n[d]                     [e]                     [f][f][f]\n                        [e]\n                        [e]\n                        [e][e][e]\n[g]                     [h]                     [i]\n[g]                     [h]\n[g]                     [h]\n                        [h]\n[j][j]                  [k]\n[j][j]                  [k]"
,"[a]                     [b]                     [c]\n                                                [c]\n                                                [c]\n[d][d][d]               [e]                     [f]\n                        [e][e][e]               [f]\n                                                [f][f][f]\n                                                   [f]\n[g][g][g]               [h][h]                  [i]\n[g][g][g]                                       [i][i]\n                                                [i][i]\n[j]                     [k]\n[j]                     [k]\n[j]"
,"[a][a]                  [b]                     [c]\n                        [b]                     [c][c][c]\n                        [b]                           [c]\n                        [b][b]                        [c]\n                           [b]\n[d]                     [e]                     [f]\n[d]\n[g]                     [h]                     [i]\n[g][g][g]               [h]                     [i]\n                        [h][h][h]               [i]\n                              [h]\n[j][j][j]               [k][k]"
,"[a][a]                  [b][b][b]               [c]\n                        [b][b][b]\n[d]                     [e]                     [f]\n[d]                     [e]                     [f]\n                        [e]                     [f]\n                        [e][e]\n                           [e]\n[g][g][g]               [h][h]                  [i]\n                        [h][h]                  [i]\n                        [h][h]                  [i][i]\n                                                   [i]\n                                                   [i]\n[j]"
,"[a][a][a]               [b][b]                  [c][c]\n                        [b][b]                  [c][c]\n                        [b][b]                  [c][c]\n[d][d]                  [e]                     [f][f]\n   [d]                  [e]\n                        [e]\n                        [e]\n                        [e]\n[g]                     [h]                     [i][i]\n[g]                                             [i][i]\n[g]\n[g]\n[g][g]"
,"[a][a][a]               [b]                     [c]\n      [a]                                       [c]\n      [a]\n[d]                     [e][e][e]               [f][f]\n[d]\n[g]                     [h][h]                  [i]\n[g][g][g]               [h][h]                  [i]\n   [g][g]                                       [i]\n[j]                     [k]\n[j]                     [k]\n[j][j]\n   [j]\n   [j]"
,"[a][a]                  [b]                     [c][c]\n                        [b][b]\n                        [b][b][b]\n[d]                     [e][e][e]               [f][f]\n                        [e][e][e]                  [f][f][f]\n[g]                     [h]                     [i][i]\n[g]                     [h]                     [i][i]\n[g]                                             [i][i]\n[j][j][j]"
,"[a][a]                  [b][b][b]               [c]\n   [a]                     [b][b]\n   [a][a][a]\n[d][d]                  [e]                     [f]\n[d][d]                  [e][e]                  [f][f][f]\n                        [e][e]\n                           [e]\n[g][g][g]               [h]                     [i]\n                                                [i]\n                                                [i]\n                                                [i]\n[j][j]"
,"[a]                     [b][b]                  [c]\n[a]                                             [c]\n[a]\n[a][a][a]\n[d]                     [e][e][e][e]            [f]\n[d]                                             [f]\n                                                [f]\n[g]                     [h]                     [i]\n[g]                     [h][h]\n[g]                     [h][h][h]\n[g]\n[g][g]\n[j]                     [k][k]\n                           [k]"
,"[a]                     [b][b]                  [c]\n[a]                     [b][b][b]               [c]\n[a][a][a][a]                                    [c]\n[d][d][d]               [e]                     [f]\n   [d][d]               [e]\n[g]                     [h]                     [i]\n                        [h]                     [i]\n                        [h]\n                        [h]\n                        [h][h]\n[j][j][j][j][j]"
,"[a][a]                  [b][b]                  [c]\n   [a][a][a]\n   [a]\n[d]                     [e][e][e]               [f][f]\n[d]\n[g]                     [h][h]                  [i]\n[g]                     [h][h]\n[g]                     [h][h]\n[g]\n[j]                     [k]\n[j][j]                  [k][k]\n                        [k][k]\n                           [k]"
,"[a][a][a]               [b]                     [c]\n                                                [c]\n                                                [c][c][c][c]\n[d]                     [e][e][e]               [f][f][f]\n[d]                     [e][e][e]               [f][f][f]\n[d]\n[g]                     [h][h]                  [i][i]\n[g]                                             [i][i]\n[j]\n[j]\n[j]"
,"[a]                     [b]                     [c][c]\n                        [b]                     [c][c]\n                        [b]\n[d][d][d]               [e]                     [f]\n      [d]                                       [f]\n                                                [f]\n[g]                     [h]                     [i]\n[g]                     [h][h][h]               [i][i]\n                        [h][h]                  [i][i][i]\n[j]                     [k]                     [l][l][l][l]"
,"[a]                     [b]                     [c]\n[a][a]                  [b]\n[a][a]\n[d]                     [e]                     [f]\n[d]                     [e]\n[d]                     [e][e][e]\n[d]                        [e]\n[g]                     [h][h][h]               [i][i]\n[g][g]\n[j][j][j]               [k]\n[j][j][j]               [k]\n                        [k]"
,"[a]                     [b]                     [c][c]\n[a][a][a]               [b]                     [c][c]\n   [a][a]               [b]\n                        [b]\n                        [b][b]\n[d]                     [e]                     [f]\n[d]                     [e]\n[d]\n[g]                     [h][h][h][h]            [i]\n[j][j]                  [k]\n                        [k]\n                        [k][k]\n                           [k]\n                           [k]"
,"[a]                     [b][b][b]               [c]\n[a]                     [b][b][b]               [c][c][c]\n[a]\n[d]                     [e]                     [f][f][f][f]\n                        [e]\n                        [e]\n                        [e]\n                        [e]\n[g]                     [h]                     [i]\n                        [h][h]                  [i]\n                        [h][h]                  [i][i][i]\n                                                   [i]\n[j]"
,"[a][a][a]               [b]                     [c]\n                        [b]                     [c]\n                        [b][b][b]\n                              [b]\n[d][d][d]               [e][e]                  [f]\n                        [e][e]                  [f]\n                                                [f]\n                                                [f][f][f]\n[g]                     [h]                     [i]\n[g]                                             [i]\n[g]                                             [i]\n                                                [i]\n                                                [i][i]\n[j][j]"
,"[a]                     [b]                     [c]\n[a]                     [b]\n[a][a]                  [b]\n[d]                     [e][e][e]               [f]\n[d]                           [e]               [f]\n                              [e]               [f]\n                              [e]               [f][f]\n                                                   [f]\n[g][g]                  [h]                     [i]\n                                                [i]\n[j][j][j]               [k]\n                        [k][k][k]\n                        [k][k]"
,"[a][a][a]               [b][b]                  [c]\n                           [b]                  [c]\n[d]                     [e][e]                  [f]\n[d]                                             [f]\n[d][d]\n   [d][d]\n[g]                     [h]                     [i]\n                        [h]\n                        [h]\n[j][j]                  [k]                     [l]\n[j][j][j]               [k]                     [l][l][l]\n      [j]               [k]"
,"[a][a]                  [b]                     [c][c][c]\n[d]                     [e][e]                  [f][f]\n[d]                     [e][e]                  [f][f]\n[d]\n[d]\n[g]                     [h][h][h]               [i]\n[g]                                             [i]\n[g]\n[g][g][g]\n[j]                     [k]\n[j]\n[j][j][j][j]"
,"[a][a][a]               [b][b]                  [c]\n[d]                     [e]                     [f]\n[d][d][d]                                       [f][f][f][f]\n[d][d]                                                   [f]\n[g][g]                  [h][h][h]               [i]\n                                                [i]\n                                                [i]\n[j]                     [k]                     [l]\n[j]                                             [l]\n                                                [l][l]\n                                                [l][l]"
,"[a][a][a]               [b]                     [c]\n                        [b]                     [c]\n                                                [c]\n[d][d]                  [e][e]                  [f]\n   [d]\n   [d]\n   [d]\n[g]                     [h]                     [i][i]\n[g][g]                  [h]                     [i][i][i]\n                        [h][h][h]                     [i]\n                              [h]\n[j][j]                  [k]\n[j][j]"
,"[a]                     [b][b][b]               [c]\n[a]                           [b]               [c]\n[a][a]                        [b]               [c]\n   [a][a]\n[d]                     [e][e][e]               [f][f]\n[d][d][d]                                       [f][f]\n   [d][d]\n[g]                     [h]                     [i][i]\n[j]                     [k]\n[j]                     [k][k]"
,"[a]                     [b]                     [c]\n                                                [c]\n                                                [c][c]\n                                                   [c][c]\n[d][d][d][d][d]         [e]                     [f][f]\n                                                [f][f]\n[g]                     [h]                     [i][i]\n[g]                     [h][h]                  [i][i]\n[g]                                             [i][i]\n[g]\n[g]\n[j][j]\n[j][j]"
,"[a]                     [b][b]                  [c][c]\n                           [b]                  [c][c]\n                           [b]\n[d][d]                  [e][e]                  [f]\n[d][d][d]               [e][e][e]\n[g]                     [h]                     [i]\n[g]                     [h]\n[g][g][g][g]            [h]\n                        [h]\n                        [h]\n[j][j][j][j]"
,"[a]                     [b][b][b]               [c][c][c]\n[a]                        [b][b]\n[a]\n[a][a]\n   [a]\n[d]                     [e]                     [f]\n[d]                                             [f]\n[d]                                             [f]\n[g]                     [h]                     [i][i]\n[g][g]                  [h]                     [i][i]\n[g][g][g]\n[j]                     [k][k]"
,"[a]                     [b][b]                  [c]\n[a]                     [b][b]\n                        [b][b]\n[d]                     [e]                     [f][f][f]\n[d][d][d]\n[d][d]\n[g]                     [h]                     [i][i]\n[g]                     [h]\n[g]\n[j][j][j]               [k]\n      [j]               [k]\n                        [k]\n                        [k][k]\n                           [k]"
,"[a][a][a]               [b]                     [c]\n   [a][a]\n[d][d][d]               [e]                     [f][f]\n                        [e]\n[g]                     [h]                     [i]\n[g][g]                  [h]                     [i]\n[g][g][g]               [h]                     [i]\n[j]                     [k][k]\n[j][j]                  [k][k][k]\n[j][j]"
,"[a][a][a]               [b]                     [c][c][c][c][c]\n   [a][a]               [b]\n      [a]               [b]\n                        [b]\n[d]                     [e]                     [f]\n[d][d]                                          [f]\n[d][d][d]                                       [f]\n[g]                     [h][h]                  [i][i][i]\n                        [h][h]                  [i][i][i]"
,"[a][a]                  [b]                     [c]\n                        [b]\n                        [b]\n[d][d][d]               [e]                     [f]\n                                                [f]\n                                                [f]\n                                                [f]\n[g][g][g]               [h][h]                  [i]\n[g][g][g]               [h][h]                  [i][i]\n                                                [i][i][i]\n[j][j][j]\n   [j][j]\n      [j]"
,"[a]                     [b]                     [c]\n[a]                                             [c]\n[a]                                             [c]\n[a]                                             [c][c][c]\n[a][a]\n[d]                     [e]                     [f]\n                        [e]\n                        [e]\n[g][g]                  [h][h]                  [i][i][i]\n[g][g]\n[g][g]\n[j]                     [k][k][k]\n[j]\n[j]\n[j]"
,"[a][a][a]               [b]                     [c]\n      [a][a]            [b][b]                  [c]\n      [a]               [b][b][b]               [c]\n                                                [c]\n[d]                     [e][e][e]               [f]\n[d][d][d]\n[d][d]\n[g]                     [h]                     [i][i]\n                                                [i][i]\n[j]                     [k][k]\n[j]"
,"[a]                     [b][b]                  [c]\n                                                [c]\n                                                [c][c]\n                                                [c][c]\n[d]                     [e][e][e]               [f][f]\n[d][d][d]                                          [f][f]\n                                                      [f]\n[g]                     [h]                     [i]\n                                                [i][i]\n                                                   [i][i]\n                                                      [i]\n[j]                     [k]                     [l][l]\n[j]\n[j]\n[j]"
,"[a]                     [b]                     [c][c][c]\n[a]                     [b]                        [c][c]\n[a]                     [b]\n[a]\n[a][a]\n[d]                     [e]                     [f][f]\n                        [e][e]\n                        [e][e]\n                           [e]\n[g]                     [h]                     [i][i]\n                                                [i][i]\n                                                [i][i]\n[j]                     [k][k][k]\n[j]"
,"[a][a][a]               [b]                     [c]\n                                                [c]\n                                                [c]\n                                                [c][c]\n                                                   [c]\n[d][d][d]               [e]                     [f]\n      [d]                                       [f]\n                                                [f]\n[g][g]                  [h]                     [i]\n                        [h]                     [i][i][i]\n                                                [i][i]\n[j][j]                  [k]\n[j][j]                  [k]\n[j][j]"
,"[a][a]                  [b][b]                  [c][c]\n                           [b][b]\n                              [b]\n[d]                     [e][e][e]               [f]\n[d]                     [e][e][e]               [f]\n[d][d]\n   [d][d]\n[g][g][g]               [h]                     [i]\n                        [h]                     [i][i]\n                        [h]\n[j]                     [k]\n                        [k]\n                        [k]"
,"[a][a][a]               [b][b]                  [c]\n      [a]                                       [c][c][c]\n                                                [c][c]\n[d]                     [e]                     [f]\n                                                [f]\n                                                [f]\n                                                [f]\n[g]                     [h][h]                  [i][i][i]\n[g]                     [h][h]\n[g]                     [h][h]\n[g][g][g]\n[j][j][j]"
,"[a][a]                  [b][b]                  [c][c][c][c][c]\n[a][a][a]                  [b]\n[d]                     [e][e][e]               [f]\n[d]                     [e][e][e]               [f]\n[d][d][d][d]                                    [f]\n                                                [f]\n                                                [f]\n[g]                     [h]\n                        [h]\n                        [h]\n                        [h]\n                        [h]"
,"[a]                     [b][b]                  [c]\n[a]                                             [c]\n[a]                                             [c]\n[a]                                             [c]\n[a]\n[d]                     [e]                     [f]\n[g]                     [h][h][h][h]            [i][i][i]\n[g]                                             [i][i][i]\n[g][g][g][g]\n[j][j]\n[j][j][j][j]"
,"[a]                     [b]                     [c]\n                        [b][b]\n                        [b][b][b]\n[d][d][d]               [e]                     [f][f]\n   [d][d]               [e]                     [f][f]\n      [d]               [e]\n                        [e]\n[g][g]                  [h]                     [i][i][i]\n                        [h]                     [i][i][i]\n                        [h]\n[j][j][j]"
,"[a][a]                  [b][b]                  [c]\n                                                [c]\n                                                [c]\n                                                [c]\n                                                [c][c]\n[d]                     [e]                     [f][f][f]\n                        [e]\n                        [e]\n                        [e][e][e]\n[g][g]                  [h]                     [i]\n                        [h][h][h]               [i]\n                        [h][h]                  [i]\n[j]                     [k]\n                        [k]\n                        [k]\n                        [k]"
,"[a]                     [b]                     [c][c][c][c][c]\n[a]\n[a][a][a][a]\n[d][d]                  [e]                     [f]\n[d][d]\n[g]                     [h][h]                  [i]\n[g]                     [h][h][h]               [i]\n[j]                     [k]\n[j]                     [k]\n[j]                     [k]\n                        [k][k]\n                           [k]"
,"[a]                     [b]                     [c]\n[a][a]                  [b]\n                        [b]\n                        [b][b]\n                           [b]\n[d]                     [e]                     [f][f][f]\n[d]                     [e]                     [f][f][f]\n                        [e]\n[g]                     [h]                     [i]\n                        [h]                     [i]\n                        [h]                     [i][i][i]\n                                                      [i]\n[j][j][j][j][j]"
,"[a]                     [b]                     [c][c]\n                        [b]                     [c][c]\n                        [b]\n                        [b]\n[d][d]                  [e][e][e]               [f][f]\n[d][d]\n[g]                     [h][h]                  [i][i]\n                        [h][h]                  [i][i]\n                        [h][h]\n[j]                     [k]\n                        [k]\n                        [k][k][k]\n                              [k]"
,"[a][a]                  [b][b]                  [c]\n   [a][a]                  [b]                  [c]\n      [a]                  [b]                  [c]\n                           [b]                  [c]\n[d]                     [e]                     [f]\n                                                [f][f]\n                                                [f][f][f]\n[g][g]                  [h][h][h]               [i]\n[j][j]                  [k][k]\n                        [k][k][k][k]"
,"[a]                     [b]                     [c]\n                                                [c]\n                                                [c]\n                                                [c][c]\n                                                   [c]\n[d]                     [e][e]                  [f][f]\n                        [e][e][e]\n                              [e]\n[g]                     [h]                     [i][i][i]\n                        [h]\n                        [h]\n                        [h]\n                        [h]\n[j][j]                  [k]                     [l]\n                        [k]                     [l]\n                                                [l][l]\n                                                   [l][l]"
,"[a][a]                  [b]                     [c]\n   [a]                                          [c][c]\n   [a]                                             [c]\n   [a]                                             [c]\n   [a]                                             [c]\n[d]                     [e]                     [f]\n[d]                                             [f]\n[d][d]                                          [f]\n   [d]                                          [f]\n   [d]\n[g][g][g]               [h][h]                  [i]\n                                                [i]\n                                                [i]\n                                                [i]\n                                                [i][i]\n[j]"
,"[a]                     [b]                     [c][c]\n                        [b]\n                        [b]\n[d]                     [e][e]                  [f]\n[d][d][d]                  [e]                  [f][f]\n[d][d]                                          [f][f][f]\n[g][g][g]               [h][h][h]               [i][i]\n                              [h][h]            [i][i]\n[j]                     [k]\n[j]"
,"[a][a][a]               [b][b]                  [c]\n                           [b]                  [c][c][c]\n                                                [c][c]\n[d]                     [e][e]                  [f][f]\n[d]                                             [f][f]\n[g]                     [h]                     [i][i][i][i]\n[g][g]                  [h]                           [i][i]\n[g][g][g]               [h]\n[j]"
,"[a][a][a]               [b]                     [c]\n                                                [c]\n                                                [c][c]\n                                                [c][c]\n[d]                     [e]                     [f]\n[d][d][d]               [e]                     [f]\n                                                [f][f]\n                                                   [f][f]\n[g]                     [h]                     [i][i]\n[g]                     [h]\n[g]                     [h]\n[j][j][j]\n[j][j]\n   [j]"
,"[a]                     [b]                     [c]\n                        [b]                     [c][c][c][c]\n                        [b]                           [c]\n[d][d]                  [e][e][e]               [f]\n[d][d][d][d]\n[g]                     [h]                     [i][i][i]\n[g]                     [h]\n[g]\n[j][j]                  [k]\n                        [k]\n                        [k][k][k]\n                              [k]"
,"[a]                     [b]                     [c]\n[a]                                             [c]\n[a]                                             [c]\n[a][a]\n   [a]\n[d]                     [e][e]                  [f][f]\n[g][g]                  [h][h][h]               [i]\n[g][g]                                          [i]\n   [g]\n[j]                     [k]                     [l]\n[j]                     [k]                     [l]\n[j][j]                  [k]\n   [j][j]"
,"[a]                     [b]                     [c][c]\n                        [b]                        [c][c]\n                        [b]                        [c][c]\n                        [b]\n                        [b][b]\n[d][d][d][d]            [e]                     [f]\n                        [e][e]\n                        [e][e]\n                           [e]\n[g]                     [h]                     [i]\n                        [h]\n                        [h]\n                        [h]\n[j]                     [k]                     [l][l]\n                                                [l][l]"
,"[a]                     [b][b][b]               [c]\n[a][a]                        [b]               [c]\n[a][a]                        [b]               [c]\n                                                [c][c][c]\n[d][d]                  [e]                     [f]\n                        [e]                     [f][f][f]\n                                                [f][f]\n[g]                     [h][h][h]               [i]\n[g]\n[g]\n[j][j][j]"
,"[a][a]                  [b][b][b]               [c]\n                              [b]               [c]\n[d]                     [e]                     [f][f][f][f]\n[d][d][d][d][d]\n[g]                     [h]                     [i]\n[g]                     [h][h][h]               [i]\n[g][g][g]                     [h][h]            [i]\n      [g]\n[j]                     [k]"
,"[a]                     [b][b][b][b]            [c]\n[a][a][a]                                       [c]\n   [a][a]                                       [c]\n[d]                     [e]                     [f]\n[d]                                             [f]\n[g][g][g]               [h]                     [i][i]\n      [g]                                       [i][i]\n[j]                     [k]\n[j]                     [k]\n[j][j]                  [k]\n   [j]\n   [j]"
,"[a][a][a]               [b]                     [c][c][c]\n   [a][a]               [b]                     [c][c][c]\n      [a]               [b]\n[d]                     [e][e][e][e]            [f]\n[d]\n[d]\n[d][d]\n   [d]\n[g]                     [h]                     [i]\n[g]\n[j]\n[j][j]\n[j][j][j]"
,"[a][a][a]               [b]                     [c]\n                        [b]\n                        [b]\n[d]                     [e]                     [f]\n[d]                     [e]                     [f][f]\n[d]\n[d][d][d]\n[g]                     [h]                     [i][i][i][i]\n[j]                     [k][k]\n[j][j]                     [k][k]\n[j][j][j]                     [k]\n                              [k]"
,"[a][a]                  [b][b][b]               [c]\n[a][a]                                          [c][c]\n                                                [c][c][c]\n[d]                     [e][e]                  [f]\n                                                [f]\n                                                [f]\n                                                [f]\n[g]                     [h]                     [i][i]\n[g][g]                  [h]                        [i]\n                        [h]\n[j][j]                  [k]\n   [j][j]\n      [j]\n      [j]"
,"[a]                     [b]                     [c][c][c][c][c]\n[a]                     [b]\n[a]\n[d][d][d]               [e]                     [f]\n[d][d][d]               [e]                     [f]\n                        [e][e]                  [f]\n                        [e][e]                  [f]\n                                                [f][f]\n[g]                     [h]                     [i][i]\n                                                [i][i]\n                                                [i][i]"
,"[a]                     [b]                     [c]\n[a]                     [b]\n[a]                     [b][b]\n[a]                        [b][b]\n[d][d][d][d]            [e]                     [f][f]\n                                                [f][f]\n[g][g]                  [h]                     [i][i]\n[g][g]                  [h][h][h]               [i][i]\n   [g][g]                                          [i]\n[j]"
,"[a]                     [b][b][b]               [c]\n[a][a][a]                     [b]\n[a][a]                        [b]\n[d][d][d]               [e]                     [f]\n                        [e][e][e]\n                        [e][e]\n[g][g]                  [h]                     [i]\n                        [h]                     [i]\n                        [h]\n[j]                     [k][k]\n[j]                     [k][k]\n[j]"
,"[a][a]                  [b][b][b][b]            [c]\n   [a][a]                                       [c]\n   [a][a]\n[d]                     [e]                     [f]\n[d]\n[d][d]\n   [d]\n   [d]\n[g][g]                  [h]                     [i]\n[g][g]                                          [i]\n[j]                     [k]\n[j]                     [k][k]\n[j]                        [k]\n                           [k]\n                           [k]"
,"[a][a]                  [b]                     [c]\n                        [b]                     [c]\n                        [b]\n[d][d][d]               [e]                     [f]\n[d][d][d]               [e]                     [f][f]\n                        [e]                     [f][f][f]\n[g]                     [h]                     [i]\n                        [h]                     [i]\n                                                [i][i]\n                                                   [i]\n                                                   [i]\n[j]                     [k]                     [l][l][l]"
,"[a]                     [b]                     [c]\n                                                [c]\n                                                [c]\n[d]                     [e][e][e]               [f]\n                                                [f]\n                                                [f]\n                                                [f][f][f]\n[g]                     [h][h][h][h]            [i]\n[g]                                             [i][i]\n                                                [i][i][i]\n[j][j]                  [k][k]\n[j][j]                     [k][k]\n                              [k]"
,"[a][a][a]               [b]                     [c]\n                        [b][b][b][b]            [c]\n                                 [b]            [c]\n[d]                     [e][e][e]               [f][f]\n[d]                     [e][e][e]\n[d][d][d][d]\n[g][g]                  [h]                     [i]\n[g][g]                  [h]\n[j][j][j]"
,"[a]                     [b][b][b]               [c]\n[a]                           [b]               [c]\n[a]                                             [c][c][c]\n                                                      [c]\n[d][d]                  [e][e][e][e]            [f]\n[d][d]\n[g]                     [h]                     [i]\n                        [h][h][h]               [i]\n                              [h][h]\n[j]                     [k][k]\n                        [k][k]"
,"[a][a][a]               [b]                     [c][c][c]\n                                                      [c]\n[d]                     [e]                     [f]\n[d]                                             [f][f][f]\n[d]                                             [f][f]\n[g]                     [h][h]                  [i]\n                        [h][h]                  [i]\n                                                [i]\n[j]                     [k]                     [l][l]\n[j]                     [k][k][k]\n                        [k][k]"
,"[a]                     [b]                     [c]\n[a]                     [b][b]\n[a]                     [b][b][b]\n[a]\n[d]                     [e]                     [f][f][f]\n[d][d]                  [e]                        [f][f]\n[d][d]                  [e]\n   [d]                  [e]\n[g][g]                  [h]                     [i]\n[j]                     [k][k][k]\n[j][j]"
,"[a][a][a][a][a]         [b]                     [c][c]\n                                                [c][c]\n[d][d][d]               [e]                     [f][f]\n[d][d][d]                                          [f]\n                                                   [f]\n[g]                     [h][h]                  [i]\n[g]                     [h][h][h]               [i]\n[g][g][g][g]                                    [i]\n                                                [i]"
,"[a][a]                  [b]                     [c][c][c]\n                        [b]\n                        [b]\n                        [b][b]\n                           [b]\n[d]                     [e][e]                  [f]\n[d]\n[d]\n[d]\n[g][g]                  [h]                     [i]\n   [g]                                          [i]\n   [g]                                          [i][i]\n                                                   [i]\n                                                   [i]\n[j]                     [k]\n                        [k][k]\n                           [k]\n                           [k][k]"
,"[a][a]                  [b]                     [c][c]\n[a][a][a]               [b][b]\n      [a]\n[d]                     [e]                     [f]\n[d]                     [e]                     [f]\n[d][d][d]               [e]\n   [d]\n[g]                     [h][h][h]               [i][i][i]\n                                                [i][i][i]\n[j][j]\n   [j]\n   [j]"
,"[a][a][a][a]            [b]                     [c]\n                                                [c][c]\n                                                [c][c][c]\n[d][d][d]               [e][e][e]               [f]\n                           [e][e]               [f]\n                                                [f]\n[g]                     [h]                     [i]\n[g]                     [h]                     [i]\n                        [h]                     [i]\n                        [h]                     [i][i][i]\n                        [h]\n[j]"
,"[a]                     [b]                     [c][c][c]\n[a]                     [b]\n[a][a]                  [b][b]\n                        [b][b]\n[d][d]                  [e]                     [f]\n   [d][d]               [e][e]\n      [d]                  [e]\n      [d]                  [e]\n                           [e]\n[g][g]                  [h]                     [i]\n                        [h]\n                        [h]\n                        [h]\n                        [h]\n[j][j]"
,"[a]                     [b][b][b][b]            [c]\n[a]\n[a][a][a][a]\n[d]                     [e]                     [f]\n[d]                     [e]                     [f]\n                        [e]                     [f]\n[g][g][g]               [h][h][h]               [i][i]\n[g][g][g]               [h][h][h]               [i][i]\n[j]"
,"[a]                     [b][b][b][b]            [c]\n[a][a]                        [b][b]\n[a][a][a]\n[d]                     [e][e]                  [f][f]\n[d]                     [e][e]                     [f]\n[d]\n[d]\n[g][g][g]               [h]                     [i]\n                        [h][h][h]\n                        [h][h]\n[j][j]"
,"[a][a]                  [b]                     [c][c][c][c][c]\n[a][a][a]\n[d][d][d]               [e]                     [f][f]\n      [d]\n      [d]\n[g]                     [h]                     [i]\n[g][g][g]               [h]                     [i]\n   [g][g]                                       [i]\n[j]\n[j]\n[j][j]\n[j][j]"
,"[a][a][a]               [b]                     [c]\n                        [b][b][b]               [c]\n                        [b][b]                  [c]\n                                                [c]\n                                                [c]\n[d][d]                  [e]                     [f][f]\n                                                [f][f]\n[g][g][g]               [h]                     [i]\n      [g]                                       [i][i]\n      [g][g]                                    [i][i][i]\n[j]\n[j]"
,"[a]                     [b][b]                  [c]\n[d]                     [e]                     [f]\n[d]\n[g][g]                  [h][h]                  [i]\n[g][g][g]                                       [i]\n      [g]                                       [i][i]\n                                                   [i][i]\n[j][j][j]               [k]                     [l]\n                        [k]                     [l]\n                        [k]                     [l]\n                                                [l][l]\n                                                   [l]\n[m]\n[m]"
,"[a]                     [b]                     [c]\n                        [b]                     [c]\n                        [b][b]\n                           [b][b]\n[d][d][d][d][d]         [e]                     [f][f][f]\n                                                [f][f][f]\n[g]                     [h]                     [i][i]\n[g]                     [h][h]                     [i][i]\n[g]                                                [i][i]\n[j]\n[j]\n[j]"
,"[a]                     [b][b][b]               [c]\n[a][a]                        [b]               [c]\n[a][a][a]                     [b][b]            [c]\n[d][d]                  [e]                     [f]\n                                                [f][f][f]\n                                                [f][f]\n[g][g][g]               [h]                     [i]\n                        [h]                     [i]\n[j][j]                  [k]\n[j][j]"
,"[a][a][a]               [b][b][b]               [c]\n      [a]               [b][b][b]               [c]\n      [a]\n[d]                     [e]                     [f]\n[d]                     [e][e][e]               [f]\n[d]                        [e][e]\n[g]                     [h]                     [i][i][i]\n[g]\n[g][g]\n   [g]\n   [g]\n[j][j]"
,"[a]                     [b]                     [c][c][c][c]\n[a][a]                  [b]\n   [a]                  [b]\n   [a][a]\n[d]                     [e]                     [f]\n                        [e]\n                        [e][e]\n                           [e]\n                           [e]\n[g][g]                  [h]                     [i]\n                        [h]                     [i]\n[j]                     [k]                     [l][l]\n                        [k]                        [l][l]\n                                                   [l][l]"
,"[a]                     [b]                     [c]\n[d]                     [e]                     [f]\n[d][d]                  [e]                     [f]\n   [d][d]               [e][e]                  [f]\n      [d]                  [e][e]\n[g]                     [h]                     [i][i][i][i]\n[g]                     [h]\n[j][j][j]               [k]\n   [j][j]               [k][k][k]\n      [j]"
,"[a]                     [b]                     [c]\n[a]\n[a]\n[a]\n[d]                     [e][e][e][e]            [f][f]\n                                                [f][f]\n[g][g][g]               [h]                     [i][i][i]\n                        [h]                     [i][i][i]\n                        [h][h][h][h]\n[j]\n[j]\n[j]\n[j][j][j]"
,"[a][a]                  [b]                     [c]\n[a][a]\n[d][d][d][d][d]         [e]                     [f]\n                        [e][e][e]               [f]\n                              [e][e]            [f]\n                                                [f]\n                                                [f]\n[g]                     [h]                     [i]\n[g]                     [h][h]\n[g][g]\n   [g][g]\n[j][j][j]\n      [j]"
,"[a]                     [b][b][b]               [c]\n[a]                           [b]               [c]\n[a][a][a]                     [b]               [c]\n                              [b]\n[d]                     [e][e]                  [f][f]\n                                                [f][f]\n[g]                     [h]                     [i]\n[g]                     [h][h][h]               [i]\n                        [h][h]                  [i]\n[j]                     [k][k][k]"
,"[a]                     [b]                     [c]\n                        [b]                     [c]\n                        [b][b]\n                        [b][b]\n[d]                     [e]                     [f]\n[d]                     [e]\n[d]                     [e]\n[d]\n[d][d]\n[g]                     [h]                     [i][i]\n[g][g]                  [h][h]                     [i]\n                           [h][h]\n                              [h]\n[j]                     [k][k][k][k]"
,"[a][a]                  [b]                     [c][c][c][c][c]\n                        [b]\n                        [b]\n[d]                     [e]                     [f][f][f]\n                        [e]                     [f][f][f]\n[g]                     [h][h]                  [i]\n                           [h]                  [i]\n                           [h]                  [i][i]\n                                                   [i][i]\n[j]\n[j]\n[j]\n[j]\n[j][j]"
,"[a][a][a]               [b][b]                  [c][c]\n                        [b][b]\n[d]                     [e]                     [f][f]\n[d]                     [e]                     [f][f]\n[d]\n[g]                     [h]                     [i]\n                        [h]                     [i][i]\n                        [h]                     [i][i][i]\n                        [h]\n                        [h]\n[j][j][j]\n   [j][j]\n      [j]"
,"[a][a]                  [b][b]                  [c]\n[a][a]                                          [c][c]\n[a][a]                                             [c]\n                                                   [c]\n                                                   [c]\n[d]                     [e][e][e]               [f]\n                                                [f]\n                                                [f]\n[g]                     [h][h][h]               [i]\n[g]                        [h][h]               [i]\n[j]\n[j]\n[j][j]\n   [j]\n   [j]"
,"[a][a]                  [b]                     [c]\n[a][a]                  [b]                     [c]\n                        [b][b][b]               [c]\n                              [b]               [c][c][c]\n[d]                     [e]                     [f][f]\n[d]\n[g][g][g]               [h][h][h]               [i]\n                                                [i]\n                                                [i]\n[j]\n[j]\n[j]\n[j]\n[j][j]"
]

to=0
function update() {
  var nt=+I.value
  var test = Test[nt-1]
  if (test) {
    O.textContent = test
    clearTimeout(to)
    to = setTimeout(_=>{
      I.disabled = true
      var t = + new Date()
      var [d,r]=F(test)
      O.textContent = 'Time '+(new Date-t)/1000+' sec'+d+r.join`\n`+'\n'+test
      I.disabled = false
    }, 800)
  }
}

update()
```

```
Test # <input id=I value=1 type=number oninput='update()' max=101 min=1> (1 to 101, be patient: some testcase is slow to solve)
<pre id=O></pre>
```
> 2 votes

---
Tags: code-golf, sequence, decision-problem, parsing, board-game
---


title: Pitch dark (Earth Hour remembrance)

text:
# Question
Title: Pitch dark (Earth Hour remembrance)
Your goal is simple: the program must turn the screen of your computer **totally black**.

After the program is started, the screen must quickly turn completely black, and remain so until the program is exited (any key, or alt+F4, mouse movement, etc.), after which things should turn back to normal. So **shutting down the computer or turning the power of the monitor off is NOT allowed**. Not a single non-black pixel should be visible during this time, not even a blinking cursor.

The user should not do any preparation (moving the mouse outside the screen, disconnecting cables, etc. or user input after the program started), just start the program.

You can safely assume the computer has only one monitor attached. We also assume a standard desktop or notebook computer, because doing it on a specific device without a normal monitor would be too simple.

If you use any external resources (a black image, a GUI file, etc.) their size in bytes is added to your code size.

It's OK if it only works on one OS family, or if it requires opengl etc., but requiring a very specific hardware configuration is frowned upon.

Your source code must be written in a programming language, not just a configuration file some other program (like a screen saver) will use.

# Answer
> 22 votes
## Bash, 28 or 12

Assuming default installation of Ubuntu 12.04 LTS.

```
gnome-screensaver-command -a

```

Automatically starts the screensaver, which is a black screen by default.

**Edit**: As suggested by @Glenn Randers-Pehrson, here's one with 12 bytes

```
/*/*/gn*d -a

```

Note that this may not work if you have another file on your system that satisfies this name, say `/tmp/1/gnd`. But it's code-golf, who cares?

---

Check out my other bash answer if you don't use Gnome screensaver!

# Answer
> 31 votes
**Assembly** (bootloader) 131 chars / 512 bytes compiled (actually smaller, but bootsector must be 512 bytes long.)

It is a simple boot loader. When computer starts, BIOS will load it from disk (floppy). Then it enters into graphics mode and just hangs. When user presses the power button, program will end and computer will enter to mode where is was before running program.

Tested with VirtualBox.

It will compile with nasm:

```
nasm -f bin file.asm -o start.img

```

Source code:

```
[BITS 16]
[ORG 0x7C00]
cli
mov AX,0x0
mov SS,AX
mov SP,0x9000
sti
mov AH,0x0
mov AL,0x13
int 0x10
times 510 - ($-$$) db 0
dw 0xAA55

```

# Answer
> 15 votes
# QBASIC (31)

```
SCREEN 7
WHILE INKEY$=""
WEND

```

# Answer
> 14 votes
# Java : 165

Simple Java, just creates a fullscreen black frame. To exit you have to Alt+Tab back to the console and Ctrl-C, but that seems simple enough.

```
import java.awt.*;class B{public static void main(String[]a){Frame f=new Frame();f.setExtendedState(6);f.setUndecorated(1>0);f.setBackground(Color.BLACK);f.show();}}

// line breaks below

import java.awt.*;
class B{
    public static void main(String[]a){
        Frame f=new Frame();
        f.setExtendedState(6);
        f.setUndecorated(1>0);
        f.setBackground(Color.BLACK);
        f.show();
    }
}

```

# Answer
> 11 votes
Applesoft \]\[ BASIC (17)

```
1 HGR2:GET X:TEXT

```

# Answer
> 11 votes
# Bash - 57 ~~26~~

```
C=/s*/*/*/*/b*ess;(A=$(cat $C);echo 0;cat;echo $A)|tee $C

```

On a laptop this will set the screen backlight brightness to 0 via `/sys/class/backlight`, on a tablet or phone this will set the screen led brightness to 0 via `/sys/class/leds`

# Answer
> 8 votes
I know this is but I couldn't resist.

Just make sure you don't have any browser windows open (in this case, Chrome);

Execute this **PitchBlack.bat (~~31~~ 24 bytes)**:

```
chrome --kiosk file:///1

```

If placed in the same directory of your *Chrome.exe* file, this batch will execute Chrome in **kiosk mode** and it will open a file called **/1 (~~49~~ ~~41~~ 34 bytes)** in fullscreen:

```
<body bgcolor=0 style=cursor:none>

```

*Et voilà!*

**Total byte count: ~~80~~ ~~72~~ 58**
Thanks to @ace :)

To exit the program, you must go for a classic **ALT+F4**; You don't actually have to do any preparation *after* the program starts (neither before, you just have to place `/1` and the batch file), so it's fine with the rules.

Please note that if you get your cursor towards the screen borders, it *may* become visible. The OP didn't say this was not allowed, since

> After the program is started, the screen must quickly turn completely black, and remain so until the program is exited (any key, or alt+F4, **mouse movement**, etc.), after which things should turn back to normal.

So this should be totally ok! :P

# Answer
> 7 votes
# C# - ~~211~~ ~~202~~ ~~200~~ ~~196~~ 179 bytes

```
using System.Windows.Forms;class A{static void Main(){Cursor.Hide();new Form{BackColor=System.Drawing.Color.Black,WindowState=(FormWindowState)2,FormBorderStyle=0}.ShowDialog();}}

```

Hides the cursor and shows a full-screen black window. Can be closed with `Alt`+`F4`

**Un-golfed code**:

```
using System.Windows.Forms;
class A
{
    static void Main()
    {
        Cursor.Hide();
        new Form
        {
            BackColor = System.Drawing.Color.Black,
            WindowState = (FormWindowState)2, // FormWindowState.Maximized
            FormBorderStyle = 0 // FormBorderStyle.None
        }.ShowDialog();
    }
}

```

I don't need to cast to `FormBorderStyle`, because that's not necessary if the integer is `0`.

# Answer
> 5 votes
# C# ~~175~~ ~~171~~ 167

```
class P{static void Main(){SendMessage(65535,274,61808,2);}[System.Runtime.InteropServices.DllImport("user32")]static extern int SendMessage(int a,int b,int c,int d);}

```

A lot of the answers here don't actually make the screen *black*: on an LCD screen, the backlight remains on and bleeds through, leaving you with a darkish grey.

This little snippet actually tells Windows to turn off the screen, the same as what the inactivity timer does (Note: this doesn't violate the "no power off" rule because it really just causes the monitor to go into standby. *Most* monitors will turn back on when input is resumed. Also, that rule's intention seems to be to make sure the program can turn it back on - see below.)

Move the mouse or press a key to turn the screen back on.

Monitor power off adapted from https://stackoverflow.com/a/713519/1030702

# Answer
> 4 votes
# Python / Pygame 199 127 125 92

```
from pygame import*;display.set_mode((9,9),-1<<31);mouse.set_visible(0)
while 1:event.pump()

```

Thanks to some tips from ace.

# Answer
> 4 votes
# Amiga assembly

ASM-One - ~~228~~ 219 chars, 172 bytes compiled (168 bytes optimized)

It's been 20 years since I last coded a single line in Amiga assembly, so bear with me. :-)

The Amiga was a bit more involved than the PC in terms of setting up a blank screen, so tried to get rid of as much setup and teardown as possible. There's no disabling of interrupts or multitasking; no double WaitTOF; no view replacement; etc. I wouldn't even have written this for the quickest and dirtiest demo. Which means this:

* is bad practice
* may not be entirely safe
* may not always work
* even with those disclaimers, probably has stupid mistakes owing to 20 years of neglected assembly.

... although it's been tested on emulated A500 and A1200, with or without fast memory. Compiles to a standard executable. Mouse click exits.

```
l=$dff080
 move.l 4,a6
 lea g,a1
 jsr -408(a6)
 move.l d0,a1
 move.l 38(a1),d4
 jsr -412(a6)
 move.l #c,l
w:btst #6,$bfe001
 bne w
 move.l d4,l
 rts
g:dc.b "graphics.library",0
 SECTION d,DATA_C
c:dc 256,512,384,0,-1,-2

```

Less golfed:

```
COP1LC equ $dff080

    move.l  $4, a6          ; ExecBase
    lea     gfxname, a1
    jsr     -408(a6)        ; OpenLibrary (old, hence no need for clearing d0)
    move.l  d0, a1
    move.l  38(a1), d4      ; store copper list
    jsr     -414(a6)        ; CloseLibrary
                            ; Yeah, if I had a penny for the times I saw that left out
                            ; but I just... can't...

    move.l  #copper,COP1LC  ; write copper list

wait:
    btst    #6, $bfe001     ; Check mouse click
    bne     wait

    move.l  d4, COP1LC      ; restore copper list
    rts

gfxname:
    dc.b    "graphics.library", 0

    SECTION data, DATA_C
copper:
    dc.w $0100, $0200       ; disable bitplanes
    dc.w $0180, $0000       ; color 0 = black
    dc.w $ffff, $fffe       ; end

```

# Answer
> 4 votes
# TI-BASIC, 7 6

```
Shade(Ymin,Ymax

```

Works both in the terminal (home screen) or as a program. Pressing `ON` or most other buttons returns to the terminal/home screen.

# Answer
> 3 votes
## sh/X11 on Arch Linux, 26

```
b=/b*/*ht;$b =0;read;$b =7

```

# Answer
> 3 votes
# Bash, 37

Uses `unclutter` to hide the mouse pointer and a fullscreen session of `xterm` to black the screen. The cursor will reappear for a moment if you move it, but if you leave it alone the screen will be black until you press Ctrl+C.

It will take a few seconds for the mouse cursor to disappear (as long as you don't move it). If this isn't fast enough, add the `-grab` option to `unclutter` for an additional 6 chars.

```
unclutter&xterm -fu -bg black -e yes ''

```

**WARNING:** this will leave a process of `unclutter` running even after you press Ctrl+C, use `killall unclutter` to stop it.

## Explanation

`unclutter &` launches `unclutter`. The `&` is there so we can get on with the next command instead of waiting for this one to terminate.

`xterm -fullscreen` launches XTerm, whose background is black by default.

The `-e yes ''` option causes XTerm to run `yes ''`, thereby printing the empty string forever. This serves to hide the terminal cursor, and also provides the Ctrl+C functionality.

# Answer
> 3 votes
## Bash, 31 (or 52)

On a TTY, use the following script (assuming your default TTY background is black, which is true at least for Ubuntu 12.04 LTS):

```
setterm -foreground black
clear

```

Your TTY would still be fully functional even after using this script :)

If this isn't allowed, use the following (52 bytes):

```
x='setterm -foreground'
$x black
clear
read
$x white

```

And press `Enter` to terminate the script.

Special thanks to @nyuszika7h.

# Answer
> 3 votes
# Commodore 64 (16 bytes)

```
ROL $A903
BRK
STA $D020
STA $D011
JSR $FF8A
JMP ($032C)

```

It has been more than 20 years since I used Turbo Assembler, so I can only provide source for use in VICE's monitor. Assemble this at $032C and `save`\[1\] through $033B. `Reset` and `LOAD"PITCHDARK",8,1`. Hit good ol' `Runstop+Restore`\[2\] to get back to normal.

How does it work?

Here's the true source:

```
032C 2E 03      .BY 2E 03
032E A9 00      LDA #$00
0330 8D 20 D0   STA $D020   ; set border color
0333 8D 11 D0   STA $D011   ; set VIC blanking mode
0336 20 15 FD   JSR $FF8A   ; reset the vectors we trampled
0339 6C 2C 03   JMP ($032C) ; call the real CLALL

```

$032C is the kernal `CLALL` or "Close All Channels And Files" vector. As part of its cleanup, the BASIC `LOAD` command does a `CLR` which in turn calls `CLALL`. We replace the `CLALL` vector with a pointer to our own routine immediately after the vector. We set the border to black and cover the screen with the border, and then call `RESTOR` at $FF8A. The last vector replaced by `RESTOR` is `SAVE` at $0332-0333 which means the last 8 bytes are undisturbed. We then exit via the restored `CLALL` vector to continue `LOAD`'s execution.

Thanks for this, it was fun trip down memory lane, relearning how to do an autorun program :)

\[1\] use save and not bsave so that load with ,1 works correctly
\[2\] Escape + PageUp in x64, probably.

# Answer
> 2 votes
# ZX Spectrum Basic (29 bytes)

```
1 FOR x=0 TO 255
2 FOR y=0 TO 175
3 PLOT x,y
4 NEXT y
5 NEXT x

```

Iterates over the screen, plotting black pixels which are automatically cleared when the program finishes.

The ZX Spectrum's edition of basic uses single bytes as commands and no newlines, if counting displayed characters you get 61 chars.

# Answer
> 2 votes
# Processing, 113

```
void setup(){noCursor();size(displayWidth, displayHeight);background(0);}boolean sketchFullScreen(){return true;}

```

I tried putting the code above onto draw() to save some bytes, but it didn't work. Press Alt-F4 to quit.

# Answer
> 2 votes
## Lua + LÖVE (50)

```
love.mouse.setVisible()love.window.setFullscreen""

```

Both functions are supposed to take a boolean argument, yet this works.

# Answer
> 2 votes
## QBasic, 9 bytes

```
CLS:SLEEP

```

`CLS` clears the screen, `SLEEP` without any arguments holds execution until a key is pressed.

# Answer
> 2 votes
# SmileBASIC, 15 bytes

```
XSCREEN 4
EXEC.

```

Pressing START or SELECT will end the program.

`XSCREEN 4` sets the display mode to show a 320\*480 image spanning both screens. This should clear everything, so an `ACLS` is not required. `EXEC.` makes the code repeat by constantly running the program in slot 0. I wasn't able to do `XSCREEN 4EXEC.` because you can't have a number directly before `E`

# Answer
> 1 votes
# Sinclair BASIC - 28 chars

```
BORDER 0:PAPER 0:CLS:PAUSE 0

```

The thing about Sinclair BASIC was each keyword had it's own character code (taking up one byte), so this would actually take up 13 bytes including spaces.

# Answer
> 1 votes
# SmileBASIC, 23 bytes

Runs forever until the program is force-killed with START or SELECT. This makes both screens *completely black*, going so far to disable 3D (thus turning off the 3D LED on o3DS.)

```
ACLS:XSCREEN 3@L GOTO@L

```

# Answer
> 1 votes
# Most POSIX compatible shells (at least `bash` and `zsh`), 21

Needs to be run on a tty

```
tput civis;clear;read

```

First command hides the cursor, second command clears the screen (duh) and third command reads a line of text

# Answer
> 0 votes
# BASH - 14 chars

`pmset sleepnow` does the job!

(typed into my Mac's Terminal)

# Answer
> 0 votes
# Bash: 48 characters

```
eval xrandr\ --output\ DP1\ --{off,auto}\;read\;

```

CW because not clear whether it qualifies due to the way it works:

* The produced black screen is real power saving: it cuts off information sending to display 1.
* Many computer displays when detect signal loss, will temporarily or periodically show their own notice.

(Note that DP1 is the first *connected* display. If you have a laptop, its embedded display is eDP1.)

# Answer
> 0 votes
# HTML Application (.hta), 102 bytes

```
<HTA:APPLICATION CAPTION=no innerborder=0 border=dialog scroll=0 windowstate=maximize><body bgcolor=0>

```

# Answer
> 0 votes
# TI-80 BASIC, 5 bytes

```
ZOOM OUT
ZOOM OUT
GRIDON

```

# Answer
> 0 votes
# Chip-8, 0 bytes

> \[T\]he original Chip-8 interpreter began execution from 0x01FC. The interpreter includes two permanent Chip-8 instructions at this location that are always executed at the start of every programme. The first of these, 0x00E0, clears the display RAM by setting all the bits to zero. The second, 0x004B, calls a machine language routine within the interpreter that switches the VIP’s display on.

Source: http://laurencescotford.co.uk/?p=75

---
Tags: code-golf
---