Skip to content

Instantly share code, notes, and snippets.

@gryte
Last active January 15, 2020 21:19
Show Gist options
  • Save gryte/b1cbb2f4bab3024fed45bbe864872a58 to your computer and use it in GitHub Desktop.
Save gryte/b1cbb2f4bab3024fed45bbe864872a58 to your computer and use it in GitHub Desktop.
Shape Area Solution With Bonus

Shape Area Challenge

n sq total sq ext. sq int.
1 1 0 1
2 5 4 1
3 13 8 5
4 25 12 13
5 41 16 25
6 61 20 41

total number of squares


n^2+(n-1)^2

  • If the current n-interesting polygon is n, then its area is n^2.
  • If the previous n-interesting polygon is (n-1), then its area is (n-1)^2
  • Thus the current area plus the previous area equals the next... n^2+(n-1)^2

exterior number of squares


4(n-1)

  • Consider each n-interesting polygon as a solid object
  • Draw the current polygon by scooting the previous polygon from its anchored center to each of the 4 different cardinal directions by 1 square (up, right, down, left) always returning to center before taking the next direction
  • The exterior squares are those added to the previous polygon which create the current
  • Visually counting just the exterior squares in each polygon (as compared to the original previous polygon) reveals a pattern also shown in the table above:
    • 2n+2(n-2)
      • 2n+2n-4
        • 4n-4
          • 4(n-1)
  • Thus the exterior area is 4 times that of the previous polygon

interior number of squares


2n^2-6n+5

  • The interior number of squares is simply the total minus the exterior
    • [n^2+(n-1)^2]-[4(n-1)]
      • n^2+n^2-2n+1-4n+4
        • 2n^2-6n+5
@MaFerLlamas
Copy link

nice

@MaFerLlamas
Copy link

what does 2n+2(n-2) in terms of the polygon? i dont understand where you obtain the 2

@gryte
Copy link
Author

gryte commented Jan 15, 2020

I apologize that it's not clear at all but it's a pattern I noticed visually and wish I could express it here in pictures. For now I'll just try with my words.

Look at each polygon like it's a square of varying resolution balancing precariously on a point. Like any reasonable square, you have two pairs of parallel sides. The first pair of sides draw at a diagonal from left to right like so, / /. These sides are n long and there are two of them. Thus this first pair can be represented as 2n. The second pair of sides draw at a diagonal from right to left like so, \ \. However where they intersect with the previous sides, we don't count (almost like an 'inner' side without which we would be left with a gap as the square increases in size). These current 'sub-sides', if you will, have a length equal to the previous polygon two spots back, so n-2. When I look two polygons back at the \ \ sides, I consider the entire length which is the length of that polygon (again, n-2). There are two of them thus we represent this pair as 2(n-2).

Combine the two pairs of sides / / + \ \ and you have 2n + 2(n-2).

n = '/'
(n-2) = '\'
2n = '/ /'
2(n-2) = '\ \'
2n + 2(n-2) = '/ / + \ \'

Does that make any sense?

@gryte
Copy link
Author

gryte commented Jan 15, 2020

It's probably more succinct if I just say that the \ side is n-2 because we're taking into account the intersection of the other side /. The intersection is at the two endpoints of the length thus n-2.

/shrug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment