Skip to content

Instantly share code, notes, and snippets.

@flpvsk
Created March 8, 2019 18:34
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/92e99d5400ffb27e671c531d2129c424 to your computer and use it in GitHub Desktop.
Save flpvsk/92e99d5400ffb27e671c531d2129c424 to your computer and use it in GitHub Desktop.
Correct Answer: 2. x = (h1 - h2) / 2

Puzzle 1

Let's say we have two rectangles. One is taller and wider than the other. We want to place and vertically center the smaller rectangle inside the larger one.

The height of the larger rectangle is h1. The height of the smaller one is h2. How do we solve for x, where x is the vertical offset of one rectangle against the other?

ex1.png

In case you'd like to take a shot at it, here are a few options:

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