Skip to content

Instantly share code, notes, and snippets.

@ryanclark2
Created August 5, 2015 19:17
Show Gist options
  • Save ryanclark2/10babfca9bd497d33fda to your computer and use it in GitHub Desktop.
Save ryanclark2/10babfca9bd497d33fda to your computer and use it in GitHub Desktop.
def strong_enough( earthquake, age )
starting_strength = 1000
cumulative_damage = 1
earthquake.each do |shockwave|
sum = 0
shockwave.each { |value| sum+=value }
cumulative_damage *= sum
end
resulting_strength = starting_strength*(1 - 0.01)**age
puts "earthquake: #{earthquake}"
puts "age: #{age}"
puts "resulting strength: #{resulting_strength}"
puts "cumulative_damage: #{cumulative_damage}"
if resulting_strength - cumulative_damage < 0
return "Needs Reinforcement!"
else
return "Safe!"
end
end
@ryanclark2
Copy link
Author

Test.assert_equals(strong_enough([[2,3,1],[3,1,1],[1,1,2]], 2), "Safe!")
Test.assert_equals(strong_enough([[5,8,7],[3,3,1],[4,1,2]], 2), "Safe!")
Test.assert_equals(strong_enough([[5,8,7],[3,3,1],[4,1,2]], 3), "Needs Reinforcement!")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment