Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Written by APAD
- Explanation for Google Foo bar’s Gearing Up for Destruction readme.txt (because the original was just too hard to understand). You can find the original file at https://pastebin.com/6n563J0b
- Let's say that you have an array of peg locations int[] pegs = {4, 30, 50}; that denotes the distance in inches from a starting point 0 to the location of each peg. This would translate to:
- Peg 1 being 4 inches away from the start
- Peg 2 being 26 inches away from Peg 1
- Peg 3 being 20 inches away from Peg 2
- We need two gears to fill the space between each peg, so let's start off with the gears for Pegs 1 and 2. With these pegs being 26 inches away from each other, it becomes obvious that the gears' radii must result in a sum of 26. For instance, gear 1 could be 20 inches and gear 2 could be 6 inches.
- However, it is not that simple, as the last gear must have double the RPM of the first gear. What this means for us is that the radius of gear 1 has to be double the length of the radius of the last gear. Because of this, the only possible combination of radii is:
- gear 1 = 12
- gear 2 = 14
- gear 3 = 6
- With this, gear 1 has double the radius of gear 3, and everything fits perfectly. This is the only combination because other combinations that still result in gear 3 having half the radius of gear 1 don't work out with the space allocated. For example, let's say that:
- gear 1 = 16
- gear 2 = 10
- gear 3 = 8
- Gear 3 has half the radius of gear 1, but gears 2 and 3 don't touch.
- The challenge is essentially to write a program that finds g1 (g1 being gear 1's radius) when
- g3 = g1 / 2
- g2 = p2 - p1 - g1
- p2 - p1 = g1 + g2
- p3 - p2 = g2 + g3
- when pegs.length is 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement