Created
September 26, 2013 04:03
-
-
Save rayning0/6709743 to your computer and use it in GitHub Desktop.
Song lengths
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
# Given: | |
# 5 songs of the following lengths in seconds | |
# 223,215,378,324,254 | |
# Goals: | |
# Assign the length set to variables | |
# Calculate the Total Length of the Playlists | |
# Express the Length in Minutes | |
# Average Song Length in Minutes | |
lengths = [223, 215, 378, 324, 254] | |
total = lengths.inject(:+) | |
totalmin = total / 60.0 | |
avglength = totalmin / lengths.size | |
puts "Total length of songs = #{total} secs" | |
puts "Total in min = #{totalmin}" | |
puts "Avg song length (min) = #{avglength}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment