Skip to content

Instantly share code, notes, and snippets.

@davidrichards
Created April 8, 2016 03:00
Show Gist options
  • Save davidrichards/b0c45891264b6ee5d67b453cb014ef48 to your computer and use it in GitHub Desktop.
Save davidrichards/b0c45891264b6ee5d67b453cb014ef48 to your computer and use it in GitHub Desktop.
Quick-entry command line number multiplier (because of some quantitative self efforts I'm doing: http://bit.ly/1MXqjTc)
#! /usr/bin/ruby
puts "Space-delimit numbers to multiply"
string = gets.chomp
until string.length == 0
numbers = string.split(/\s+/).map(&:to_f)
result = numbers.reduce(1.0) {|p, e| p * e}
puts "Input: #{numbers.inspect}", "Result: ", result, "Another? (return nothing to quit)"
string = gets.chomp
end
puts "Have a #{%w(great wonderful choodesno unbelievable fantastic worthwhile productive enlightened).sample} day!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment