Skip to content

Instantly share code, notes, and snippets.

@flpvsk
Created March 8, 2019 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flpvsk/e33a78a67a06ccbd9f80498140acd79d to your computer and use it in GitHub Desktop.
Save flpvsk/e33a78a67a06ccbd9f80498140acd79d to your computer and use it in GitHub Desktop.
Correct Answer: 1. x = h3 * round((h1 - h2) / (2 * h3))

Puzzle 2

Now we'd like to tie the upper side of the smaller rectangle to a grid. The rest is the same. We are still centering the smaller box within a larger one, only this time rounding the value of x to the closest grid row.

The height of a grid row is h3.

Puzzle: center a rectangle within a grid

Here are the options:

1. x = h3 * round((h1 - h2) / (2 * h3))
2. x = h3 * (h1 - h2) / 2
3. x = h3 * floor((h1 + h2) / 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment