Last active
November 29, 2017 21:37
-
-
Save schneidmaster/4186a9d78164dbc46c17df4981ae7edf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Problem: https://twitter.com/AtticusGF/status/935977894651691008 | |
# | |
# Stage 1 has 7 disks | |
# Stage 2 has 16 disks (or 7 + 3^2) | |
# Stage 3 has 41 disks (or 16 + 5^2) | |
# Stage 4 has 90 disks (or 41 + 7^2) | |
# so for each stage, add the incrementor squared and then | |
# increase the incrementor by 2 | |
# Print off every million to avoid wasting too much | |
# time with terminal output | |
stage = 1 | |
squared_incrementer = 3 | |
disks = 7 | |
target_stage = 1234567890 | |
while stage <= target_stage | |
puts "stage #{stage}: #{disks}" if stage % 1000000 == 0 || stage == target_stage | |
disks += squared_incrementer * squared_incrementer | |
squared_incrementer += 2 | |
stage += 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment