Advertisement
apad464

Gearing Up for Destruction Explanation

Apr 12th, 2022 (edited)
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. Written by APAD
  2.  
  3. 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
  4.  
  5. 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:
  6.  
  7. Peg 1 being 4 inches away from the start
  8. Peg 2 being 26 inches away from Peg 1
  9. Peg 3 being 20 inches away from Peg 2
  10.  
  11. 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.
  12.  
  13. 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:
  14.  
  15. gear 1 = 12
  16. gear 2 = 14
  17. gear 3 = 6
  18.  
  19. 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:
  20.  
  21. gear 1 = 16
  22. gear 2 = 10
  23. gear 3 = 8
  24.  
  25. Gear 3 has half the radius of gear 1, but gears 2 and 3 don't touch.
  26.  
  27. The challenge is essentially to write a program that finds g1 (g1 being gear 1's radius) when
  28.  
  29. g3 = g1 / 2
  30. g2 = p2 - p1 - g1
  31. p2 - p1 = g1 + g2
  32. p3 - p2 = g2 + g3
  33.  
  34. when pegs.length is 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement