Created
August 5, 2015 19:17
-
-
Save ryanclark2/10babfca9bd497d33fda 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!")