Created
June 15, 2013 14:34
-
-
Save jamesmichiemo/5788340 to your computer and use it in GitHub Desktop.
Another expression using Ruby with a Rails lib
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
require 'active_support/core_ext/enumerable.rb' # < array.sum with rails installed. (bit.ly/mCblb) | |
# Podcast | |
# | |
print "Terrance has a weekly podcast and he would like to know the total amount of listeners last weekend. Calculate the sum of downloads for the week.\n\n" | |
downloadsWeek = [] | |
print "How many downloads were there on Sunday?" | |
sunDL = gets.chomp().to_i | |
downloadsWeek.push(sunDL) | |
print "How about on Monday?" | |
monDL = gets.chomp().to_i | |
downloadsWeek.push(monDL) | |
print "On Tuesday?" | |
tueDL = gets.chomp().to_i | |
downloadsWeek.push(tueDL) | |
print "Wednesday?" | |
wedDL = gets.chomp().to_i | |
downloadsWeek.push(wedDL) | |
print "Thursday?" | |
thuDL = gets.chomp().to_i | |
downloadsWeek.push(thuDL) | |
print "Friday?" | |
friDL = gets.chomp().to_i | |
downloadsWeek.push(friDL) | |
print "Saturday?" | |
satDL = gets.chomp().to_i | |
downloadsWeek.push(satDL) | |
puts "Terrance had #{downloadsWeek.sum} total downloads over the week." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment