Skip to content

Instantly share code, notes, and snippets.

@rayning0
Created September 26, 2013 04:03
Show Gist options
  • Save rayning0/6709743 to your computer and use it in GitHub Desktop.
Save rayning0/6709743 to your computer and use it in GitHub Desktop.
Song lengths
# 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