Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'A more functional command-line calculator' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A more functional command-line calculator
Authored by: mkomitee on Jul 09, '07 08:25:15PM
If you're considering something like commandline python, then you may want to give ruby a shot, which allows you to have a config file automatically import (include in ruby-ese) modules. ie, if i set my ~/.irbrc to include the following line:
include Math
I can do the following:

avalon:~ mkomitee$ irb
irb(main):001:0> (4.0*10+9*(100+1)/2.0)/cos(1)
=> 915.228372393218
irb(main):002:0> foo = cos(1)
=> 0.54030230586814
irb(main):003:0> 10 * foo
=> 5.4030230586814
irb(main):004:0> quit
avalon:~ mkomitee$ 
-- not that this is the easiest solution, but it's pretty powerful, and with the config file you don't have to include Math manually everytime you want. If you learn a little ruby, it goes a long way and you can do stuff like this in your config file:

require 'rubygems'
include Math
require "math/statistics"
class Array
  include Math::Statistics
end
and then do stuff like this:

avalon:~ mkomitee$ irb
irb(main):001:0> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].avg
=> 5.5
irb(main):002:0> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].std
=> 2.87228132326901
irb(main):003:0> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].var
=> 8.25
irb(main):004:0> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].min
=> 1
irb(main):005:0> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].max
=> 10
irb(main):006:0>quit
and with things like this, it'll become pretty easy for you to extend your own calculator.

[ Reply to This | # ]