Where in the Square?

Another week, another riddler. This week’s was a puzzle I’d submitted:

 

You are given an empty 4-by-4 square and one marker. You can color in the individual squares or leave them untouched. After you color as many or as few squares as you’d like, I will secretly cut out a 2-by-2 piece of it and then show it to you without rotating it. You then have to tell me where it was (e.g., “top middle” or “bottom right,” etc.) in the original 4-by-4 square.

Can you design a square for which you’ll always know where the piece came from?

 

For this I brute forced the problem and checked every possible square — turns out there are 6188 correct answers. Here are 150 of them:

Figure_1.png

And here is the code:

from matplotlib import pyplot as plt
from matplotlib.colors import ListedColormap
import numpy as np

def render_square(sq):
    plt.matshow(sq,cmap=plt.cm.ocean)
    plt.xticks([])
    plt.yticks([])
    plt.show()

def render_squares(total_sqs):

    rows = 10
    cols = 15
    newcmp = ListedColormap(['#F29A8B','#30333A'])
    fig, axes = plt.subplots(nrows=rows, ncols=cols, sharex=True, sharey=True)

    for x in range(cols):
        for y in range(rows):
            axes[y,x].matshow(total_sqs[x*cols + y],cmap=newcmp)
            axes[y,x].set_axis_off()

    plt.axis('off')
    fig.subplots_adjust(left=0, right=1, top=1, bottom=0, wspace=0.1, hspace=0.1)
    fig.patch.set_facecolor('#F6EEDA')
    plt.show()

def check_if_locatable(source):
    squares = set()

    #top_left
    squares.add(str([0],source[0][1],source[1][0],source[1][1]]))

    #top_middle
    squares.add(str([1],source[0][2],source[1][1],source[1][2]]))

    #top_right
    squares.add(str([2],source[0][3],source[1][2],source[1][3]]))

    #mid_left
    squares.add(str([0],source[1][1],source[2][0],source[2][1]]))

    #mid_middle
    squares.add(str([1],source[1][2],source[2][1],source[2][2]]))

    #mid_right
    squares.add(str([2],source[1][3],source[2][2],source[2][3]]))

    #bot_left
    squares.add(str([0],source[2][1],source[3][0],source[3][1]]))

    #bot_middle
    squares.add(str([1],source[2][2],source[3][1],source[3][2]]))

    #bot_right
    squares.add(str([2],source[2][3],source[3][2],source[3][3]]))

    if len(squares) == 9: return True

def check_all_squares():
    total_sq = 0
    total_sqs = []
    
    sq_size = 4
    sq_cells = sq_size**2
    bin_max = 2**sq_cells
    for i in range(bin_max):
        sq = []
        sq_vals = str(bin(i)[2:]).zfill(sq_cells)
        for row in range(sq_size):
            row_val = sq_vals[row*sq_size:(row+1)*sq_size]
            row_val_list = list(row_val)
            for i in range(sq_size): row_val_list[i] = int(row_val_list[i])

            sq.append(row_val_list)

        if check_if_locatable(sq):
            total_sq += 1
            total_sqs.append(sq)

    render_squares(total_sqs)

check_all_squares()


2 thoughts on “Where in the Square?

  1. Pingback: Can You Escape This Enchanted Maze?

  2. Pingback: Can You Escape This Enchanted Maze? – SUFFA NEWS PAPER

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s