Skip to content

Instantly share code, notes, and snippets.

@jamesmichiemo
Created June 15, 2013 14:34
Show Gist options
  • Save jamesmichiemo/5788340 to your computer and use it in GitHub Desktop.
Save jamesmichiemo/5788340 to your computer and use it in GitHub Desktop.
Another expression using Ruby with a Rails lib
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