Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save paulcalcraft/60fc552fe7e0f971dcec3d8f6172d172 to your computer and use it in GitHub Desktop.
Save paulcalcraft/60fc552fe7e0f971dcec3d8f6172d172 to your computer and use it in GitHub Desktop.
SYSTEM
You are an expert at solving visual puzzles.
USER
We are analyzing an array of pixels to test a system's ability to reason. Our goal is to extract "objects" from a pixel array by distinguishing what is the background, what are empty pixels, and what is part of a solid object. The following describes the algorithm to follow.
1) We are using a coordinate system that is composed of the following:
- Pixel grids must be rectangular or square in their arrangement, as they are meant to represent a screen. Pixels can be one of ten values: 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9.
2) Pixels with a value of 0 are considered empty.
3) All other pixel values represent either the background or an object. An object is represented by any pixel whose value is between 1 and 9. The background can be any value between 1 and 9.
4) Pixels are said to be "adjacent"(or in other words, next to each other) if they are vertically, horizontally or diagonally next to each other. A colored pixel having a single colored pixel to its left or to its right, or a colored pixel both to its left and to its right, means it is "adjacent" to the pixels next to it. Below are examples of how and when colored pixels can be "adjacent".
- All of the following pixels with the value of 2 are "adjacent" to another pixel. There are eight example pixel grids below. Study them carefully.
[0, 0, 2, 2, 2, 2, 2] -> This pixel list has seven(7) pixels. In this pixel list, the five(5) rightmost pixels are "adjacent" to each other. We count them like the following:
[0(empty), 0(empty), 2(not isolated due to pixel on the right also being colored; Count: one), 2(not isolated due to pixels to the right and left also being colored; Count: two), 2(not isolated due to pixels to the right and left also being colored; Count: three), 2(not isolated due to pixels to the right and left also being colored; Count: four), 2(not isolated due to pixel on the left also being colored, and to the right is the end of the pixel list; Count: five)]
We find that the five(5) rightmost pixels are "adjacent".
[0, 0, 2, 2, 2, 0, 0] -> This pixel list has seven(7) pixels. In this pixel list, the three(3) middle pixels are "adjacent" to each other. We count them like the following:
[0(empty), 0(empty), 2(not isolated due to pixel on the right also being colored; Count: one), 2(Count: two), 2(not isolated due to pixel on the left also being colored; Count: three), 0(empty), 0(empty)]
We find that the three(3) middle pixels are "adjacent".
[0, 0, 2, 2, 2, 2, 2, 2, 2, 0, 0] -> This pixel list has eleven(11) pixels. In this pixel list, the seven(7) middle pixels are "adjacent" to each other. We count them like the following:
[0(empty), 0(empty), 2(not isolated due to pixel to the right also being colored, regardless of the empty pixel to the left; Count: one), 2(not isolated due to pixels to the right and left also being colored; Count: two), 2(not isolated due to pixels to the right and left also being colored; Count: three), 2(not isolated due to pixels to the right and left also being colored; Count: four), 2(not isolated due to pixels to the right and left also being colored; Count: five), 2(not isolated due to pixels to the right and left also being colored; Count: six), 2(not isolated due to pixel on the left also being colored, regardless of the pixel to the right being empty; Count: seven), 0(empty), 0(empty)]
We find that the seven(7) middle pixels are "adjacent".
[2, 0, 2, 0, 2, 2, 2] -> This pixel list has seven(7) pixels. In this pixel list, only the three(3) rightmost pixels are "adjacent". The other pixels are not directly "adjacent" to another colored pixel, due to empty pixels between them. We count them like the following:
[2(isolated due to the pixel to the right being empty, and to the left is the start of the pixel list), 0(empty), 2(isolated), 0(empty), 2(not isolated due to pixel to the right also being colored, regardless of the empty pixel to the left; Count: one), 2(not isolated due to pixels to the right and left also being colored; Count: two), 2(not isolated due to pixel to the left also being colored, and to the right is the end of the pixel list; Count: three)]
We find that the three(3) rightmost pixels are "adjacent".
[2, 2, 2, 0, 2, 0, 2] -> This pixel list has seven(7) pixels. In this pixel list, only the three(3) leftmost pixels are "adjacent". The other pixels are not directly "adjacent" to another colored pixel, due to empty pixels between them. We count them like the following:
[2(not isolated due to pixel to the right being colored, and regardless of the start of the pixel grid being to the left; Count: one), 2(not isolated due to pixels to the right and left also being colored; Count: two), 2(not isolated due to pixel to the left also being colored, regardless of the empty pixel to the right; Count: three), 0(empty), 2(isolated), 0(empty), 2(isolated due to the pixel to the left being empty, and to the right is the end of the pixel list)]
We find that the three(3) leftmost pixels are "adjacent".
[2, 2, 2, 2, 2, 2, 2, 0, 2, 0, 2] -> This pixel list has eleven(11) pixels. In this pixel list, only the seven(7) leftmost pixels are "adjacent". The other pixels are not directly "adjacent" to another colored pixel, due to empty pixels between them. We count them like the following:
[2(not isolated due to pixel to the right being colored, and regardless of the start of the pixel grid being to the left; Count: one), 2(not isolated due to pixels to the right and left also being colored; Count: two), 2(Count: three), 2(not isolated due to pixels to the right and left also being colored; Count: four), 2(not isolated due to pixels to the right and left also being colored; Count: five), 2(Count: six), 2(not isolated due to pixel to the left also being colored, regardless of the empty pixel to the right; Count: seven), 0(empty), 2(isolated), 0(empty), 2(isolated due to the pixel to the left being empty, and to the right is the end of the pixel list)]
We find that the seven(7) leftmost pixels are "adjacent".
[2, 0, 2, 0, 2, 2, 2, 2, 2, 2, 2] -> This pixel list has eleven(11) pixels. In this pixel list, only the seven(7) rightmost pixels are "adjacent". The other pixels are not directly "adjacent" to another colored pixel, due to empty pixels between them. We count them like the following:
[2(isolated due to the pixel to the right being empty, and to the left is the start of the pixel list), 0(empty), 2(isolated), 0(empty), 2(not isolated due to pixel to the right also being colored, regardless of the empty pixel to the left; Count: one), 2(not isolated due to pixels to the right and left also being colored; Count: two), 2(not isolated due to pixels to the right and left also being colored; Count: three), 2(not isolated due to pixels to the right and left also being colored; Count: four), 2(not isolated due to pixels to the right and left also being colored; Count: five), 2(not isolated due to pixels to the right and left also being colored; Count: six), 2(not isolated due to pixel to the left also being colored, and to the right is the end of the pixel list; Count: seven)]
We find that the seven(7) rightmost pixels are "adjacent".
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 0, 2] -> This pixel list has nineteen(19) pixels. In this pixel list, only the fifteen(15) leftmost pixels are "adjacent". The other pixels are not directly "adjacent" to another colored pixel, due to empty pixels between them. We count them like the following:
[2(not isolated due to pixel to the right being colored, and regardless of the start of the pixel grid being to the left; Count: one), 2(not isolated due to pixels to the right and left also being colored; Count: two), 2(not isolated due to pixels to the right and left also being colored; Count: three), 2(not isolated due to pixels to the right and left also being colored; Count: four), 2(not isolated due to pixels to the right and left also being colored; Count: five), 2(not isolated due to pixels to the right and left also being colored; Count: six), 2(not isolated due to pixels to the right and left also being colored; Count: seven), 2(not isolated due to pixels to the right and left also being colored; Count: eight), 2(not isolated due to pixels to the right and left also being colored; Count: nine), 2(not isolated due to pixels to the right and left also being colored; Count: ten), 2(not isolated due to pixels to the right and left also being colored; Count: eleven), 2(not isolated due to pixels to the right and left also being colored; Count: twelve), 2(not isolated due to pixels to the right and left also being colored; Count: thirteen), 2(not isolated due to pixels to the right and left also being colored; Count: fourteen), 2(not isolated due to pixel to the left also being colored, regardless of the empty pixel to the right; Count: fifteen), 0(empty), 2(isolated), 0(empty), 2(isolated due to the pixel to the left being empty, and to the right is the end of the pixel list)]
We find that the fifteen(15) rightmost pixels are "adjacent".
- The following are examples where pixels with the value of 2 are not "adjacent" to each other due to intervening empty pixels. There are two example pixel grids below. Study them carefully.
[2, 0, 2, 0, 2, 0, 2, 0, 2] -> This pixel list has nine(9) pixels. In this pixel list, none of the pixels are "adjacent". We count them like the following:
[2(isolated due to the pixel to the right being empty, and to the left is the start of the pixel list), 0(empty), 2(isolated due to the pixel to the left and right being empty), 0(empty), 2(isolated due to the pixel to the left and right being empty), 0(empty), 2(isolated due to the pixel to the left and right being empty), 0(empty), 2(isolated due to the pixel to the left being empty, and to the right is the end of the pixel list)]
We find that none of the pixels are "adjacent".
[0, 2, 0, 2, 0, 2, 0, 2, 0] -> This pixel list has nine(9) pixels. In this pixel list, none of the pixels are "adjacent". We count them like the following:
[0(empty), 2(isolated), 0(empty), 2(isolated), 0(empty), 2(isolated), 0(empty), 2(isolated), 0(empty)]
5) The following is how to know if a pixel belongs to an object or the background.
- If a pixel is empty, it is part of the background. An example pixel grid with all empty pixels is below. Study it carefully.
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
- If a pixel is a color between 1 and 9, but it is surrounded by empty pixels, it is part of the background.
- If a pixel has value between 1 and 9, and "adjacent" to another pixel of a different value, it is part of the background.
- If a pixel has value between 1 and 9, and "adjacent" to another pixel of the same value, it is part of an object.
6) The following is how to identify the object we need to extract.
- The object composed of the largest amount of pixels "adjacent" to each other of the same value, that forms a valid square or rectangle of "adjacent" pixels, is the object we need to extract.
7) The following is how to extract the object we have chosen.
- First, we count the number of pixels wide and tall, that the object is, at the largest. This will allow us to know what size of bounding box to create, and how to copy the object to a final pixel grid, which is the size of the bounding box.
Below is how to count the pixels of an arbitrary object, presented on a pixel grid with a background of empty pixels as well as colored pixels that blend in with the actual object we want to extract, so you can clearly see how to count them.
[0, 0, 2, 2, 2, 0, 0],
[2, 2, 2, 2, 2, 2, 2],
[0, 0, 2, 2, 2, 0, 0],
[2, 2, 2, 2, 2, 2, 2],
[0, 0, 0, 0, 0, 0, 0],
[2, 2, 2, 2, 2, 2, 2]
The pixel grid above has six(6) rows and seven(7) columns. Rows and columns are analyzed in a pixel list represented as left to right. We will analyze the pixel grid above with the algorithm below.
We state that we are now going to analyze the rows.
We now analyze the rows step-by-step:
Row number 1 has three(3) middle pixels that are "adjacent" to each other, so we count them like the following:
Row number 1: [0, 0, 2, 2, 2, 0, 0],
[0(empty), 0(empty), 2(not isolated due to pixel to the right also being colored, regardless of the empty pixel to the left; Count: one), 2(Count: two), 2(not isolated due to pixel to the left also being colored, regardless of the empty pixel to the right; Count: three), 0(empty), 0(empty)]
We find that the three(3) middle pixels are "adjacent".
Row number 2 has seven(7) pixels that are "adjacent" to each other, so we count them like the following:
Row number 2: [2, 2, 2, 2, 2, 2, 2],
[2(not isolated due to pixel to the right being colored, and regardless of the start of the pixel grid being to the left; Count: one), 2(not isolated due to pixels to the right and left also being colored; Count: two), 2(not isolated due to pixels to the right and left also being colored; Count: three), 2(not isolated due to pixels to the right and left also being colored; Count: four), 2(not isolated due to pixels to the right and left also being colored; Count: five), 2(not isolated due to pixels to the right and left also being colored; Count: six), 2(not isolated due to pixel to the left also being colored, and to the right is the end of the pixel list; Count: seven)]
We find that that all seven(7) pixels are "adjacent".
Row number 3 has three(3) middle pixels that are "adjacent" to each other, so we count them like the following:
Row number 3: [0, 0, 2, 2, 2, 0, 0],
[0(empty), 0(empty), 2(not isolated due to pixel to the right also being colored, regardless of the empty pixel to the left; Count: one), 2(Count: two), 2(not isolated due to pixel to the left also being colored, regardless of the empty pixel to the right; Count: three), 0(empty), 0(empty)]
We find that the three(3) middle pixels are "adjacent".
Row number 4 has seven(7) pixels that are "adjacent" to each other, so we count them like the following:
Row number 4: [2, 2, 2, 2, 2, 2, 2],
[2(not isolated due to pixel to the right being colored, and regardless of the start of the pixel grid being to the left; Count: one), 2(not isolated due to pixels to the right and left also being colored; Count: two), 2(not isolated due to pixels to the right and left also being colored; Count: three), 2(not isolated due to pixels to the right and left also being colored; Count: four), 2(not isolated due to pixels to the right and left also being colored; Count: five), 2(not isolated due to pixels to the right and left also being colored; Count: six), 2(not isolated due to pixel to the left also being colored, and to the right is the end of the pixel list; Count: seven)]
We find that that all seven(7) pixels are "adjacent".
Row number 5 has no pixels that are "adjacent" to each other, so we count them like the following:
Row number 5: [0, 0, 0, 0, 0, 0, 0],
[0(empty), 0(empty), 0(empty), 0(empty), 0(empty), 0(empty), 0(empty)]
We find all pixels are empty.
Row number 6 has seven(7) pixels that are "adjacent" to each other, so we count them like the following:
Row number 6: [2, 2, 2, 2, 2, 2, 2]
[2(not isolated due to pixel to the right being colored, and regardless of the start of the pixel grid being to the left; Count: one), 2(not isolated due to pixels to the right and left also being colored; Count: two), 2(not isolated due to pixels to the right and left also being colored; Count: three), 2(not isolated due to pixels to the right and left also being colored; Count: four), 2(not isolated due to pixels to the right and left also being colored; Count: five), 2(not isolated due to pixels to the right and left also being colored; Count: six), 2(not isolated due to pixel to the left also being colored, and to the right is the end of the pixel list; Count: seven)]
We find that that all seven(7) pixels are "adjacent".
We state that we are finished analyzing the rows.
Explanation:
Since we are looking for a shape that is a rectangle or square, that blends into the background of the same color, we only seek the the pixels that extend farthest in the pixel grid, but importantly, with empty pixels at one or both sides. Since we just checked the rows of this arbitrary pixel grid, we see that the pixels that are "adjacent" to each other, across the entirety of the rows, must be part of the background, as a key feature of background pixels is they always go across the entire pixel grid(in this case, across the rows).
We state the count of "adjacent pixels" at their widest, that are not part of the background, are: three(3) pixels
The object is now known to be three(3) pixels wide.
We state that we are now going to analyze the columns.
We print the pixel grid again for reference.
[0, 0, 2, 2, 2, 0, 0],
[2, 2, 2, 2, 2, 2, 2],
[0, 0, 2, 2, 2, 0, 0],
[2, 2, 2, 2, 2, 2, 2],
[0, 0, 0, 0, 0, 0, 0],
[2, 2, 2, 2, 2, 2, 2]
We now analyze the columns step-by-step:
<Analyze columns>
We state that we are finished analyzing the columns.
Explanation:
Since we are looking for a shape that is a rectangle or square, and since we just checked the columns of this arbitrary pixel grid, this means we now just need to to look for the longest amount of "adjacent" pixels we found in the columns, since we have confirmed that in this case, the background pixels of the same color as the object we seek are found going across rows, not columns. We see that the 4 "adjacent" pixels repeats across multiple columns, so that must be how tall the square or rectangle we seek is.
We state the count of "adjacent pixels" at their tallest: four(4) pixels
The object is now known to be four(4) pixels tall.
-Next we create a bounding box of empty pixels that match the size of the object.
The object is three(3) pixels wide, and four(4) pixels tall, so the bounding box must be three(3) pixels wide, and four(4) pixels tall. Below we create a pixel grid the size of the bounding box.
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
-Next, simply fill the bounding box with the color of the object.
[2, 2, 2],
[2, 2, 2],
[2, 2, 2],
[2, 2, 2]
The above finishes our algorithm.
REMEMBER: if the bounding box at the end, is less tall than it is wide, make it as tall as it is wide before filling it.
Please solve the pixel grid below. Do not use python. Take a deep breath. Please think carefully.
[0,7,7,0,0],
[0,7,7,0,0],
[0,0,0,0,0],
[8,8,8,8,8],
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,2,2,0],
[0,0,2,2,0],
[0,0,0,0,0],
[0,0,0,0,0]
ASSISTANT
First, let's analyze the rows:
Row 1: [0,7,7,0,0] -> The two 7s are adjacent.
Row 2: [0,7,7,0,0] -> The two 7s are adjacent.
Row 3: [0,0,0,0,0] -> No adjacent pixels.
Row 4: [8,8,8,8,8] -> All five 8s are adjacent.
Row 5: [0,0,0,0,0] -> No adjacent pixels.
Row 6: [0,0,0,0,0] -> No adjacent pixels.
Row 7: [0,0,2,2,0] -> The two 2s are adjacent.
Row 8: [0,0,2,2,0] -> The two 2s are adjacent.
Row 9: [0,0,0,0,0] -> No adjacent pixels.
Row 10: [0,0,0,0,0] -> No adjacent pixels.
Now, let's analyze the columns:
Column 1: [0,0,0,8,0,0,0,0,0,0] -> No adjacent pixels.
Column 2: [7,7,0,8,0,0,0,0,0,0] -> The two 7s are adjacent.
Column 3: [7,7,0,8,0,0,2,2,0,0] -> The two 7s and the two 2s are adjacent.
Column 4: [0,0,0,8,0,0,2,2,0,0] -> The two 2s are adjacent.
Column 5: [0,0,0,8,0,0,0,0,0,0] -> No adjacent pixels.
From the analysis, we can see that the object composed of the largest amount of pixels "adjacent" to each other of the same value, that forms a valid square or rectangle of "adjacent" pixels, is the object composed of 8s. It is 5 pixels wide and 1 pixel tall.
However, since the bounding box at the end is less tall than it is wide, we make it as tall as it is wide before filling it. So, the bounding box will be 5 pixels wide and 5 pixels tall.
The bounding box of empty pixels that match the size of the object:
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0]
Filling the bounding box with the color of the object:
[8,8,8,8,8],
[8,8,8,8,8],
[8,8,8,8,8],
[8,8,8,8,8],
[8,8,8,8,8]
So, the extracted object is a 5x5 square of 8s.
USER
### NOTES ADDED AFTER TEST
This is an example using the initial prompt from the section 4 test 1 example: https://chat.openai.com/share/fa3c2b93-c911-4439-ba59-7567f335974a
on section 7 test task 1's input.
The input was:
[0,7,7,0,0],
[0,7,7,0,0],
[0,0,0,0,0],
[8,8,8,8,8],
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,2,2,0],
[0,0,2,2,0],
[0,0,0,0,0],
[0,0,0,0,0]
The correct answer was:
[7,7],
[7,7],
[2,2],
[2,2]
(2 separate squares)
The given answer was:
[8,8,8,8,8],
[8,8,8,8,8],
[8,8,8,8,8],
[8,8,8,8,8],
[8,8,8,8,8]
It incorrectly identified the row of 8's as the target rectangle, then expanded it to fill a square bounding box.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment