Skip to content

Instantly share code, notes, and snippets.

@schneidmaster schneidmaster/disks.rb
Last active Nov 29, 2017

Embed
What would you like to do?
# 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
You can’t perform that action at this time.