Skip to content

Instantly share code, notes, and snippets.

@jfkelley
Created August 4, 2023 20:47
Show Gist options
  • Save jfkelley/a383f29096179d688d88ea04080069fa to your computer and use it in GitHub Desktop.
Save jfkelley/a383f29096179d688d88ea04080069fa to your computer and use it in GitHub Desktop.

Consider a braille grid with m rows and n columns. Set aside the empty pattern for now, and consider non-empty patterns.

Call a pattern "canonical" iff there is at least one dot in the top row and at least one dot in the left-most column. Then no two canonical patterns are translations of each-other. Canonical patterns cannot be translated up or left, and if they are translated right or down, there would be no dots in the top or left, so the result would be non-canonical. So then we must simply count canonical patterns. Conversely, a non-canonical pattern can always be translated to a canoncial pattern by translating it up and left as much as possible.

First, consider the top row and left column together:

  • There are 2^(m+n-1) ways to place dots in that row and column
  • Of those, 2^(m-1) have an empty top row
  • Similarly, 2^(n-1) have an empty left column
  • And only 1 has an empty row and column
  • By Inclusion-exclusion principle, the number of ways to place dots in the top row and left column with at least one dot in the row and in the column is: 2^(m+n-1)-2^(m-1)-2^(n-1)+1

Next we only need to consider the rest of the grid, which is completely free. So there are 2^((m-1)(n-1)) ways to fill it in.

Then the final count of non-empty canonical patterns is simply the product of those two, and we can add 1 for the empty pattern: 2^((m-1)(n-1))(2^(m+n-1)-2^(m-1)-2^(n-1)+1)+1

For the usual 3x2 case, this comes out to 45.

For the 6x4 case, it's 15499265

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