Results 1 to 3 of 3

Thread: Simple Arithmetic Program (help pls)

  1. #1
    Join Date
    Apr 2009
    Calgary, AB, Canada
    Ubuntu Studio 9.04 Jaunty Jackalope

    Simple Arithmetic Program (help pls)

    I have a simple mathematical process i would like to automate with a program of some sort. Maybe even a basic shell script. I would like to have the user specify (or be prompted for) a few variables "A" "B" "C" and "M". Where A,B, and C are values in units of time aka HMS (hh.mmss). And M is in units of MiB.

    A+B+C=TT (in HMS, whats the syntax for adding HMS units in the shell?)

    A HMS-> / TT HMS-> = AX (unitless factor)

    Where "HMS->" (aka HMS OUT) means to convert HMS to a decimal number (unitless).

    And repeat for B and C, resulting in AX,BX, and CX.

    Then simply:

    AX*M=AS (in MiB)
    BX*M=BS (in MiB)
    CX*M=CS (in MiB)

    The desired output would be the numerical values of AS,BS, and CS.

    I know theres probably many ways to do this, any suggestions would be helpful. To keep it simple i would prefer a simple bash script if possible.
    "Those folks who try to impose analog rules on digital content will find themselves on the wrong side of the tidal wave."
    -Mark Shuttleworth (CEO Canonical/Ubuntu)

  2. #2
    Join Date
    Dec 2006
    Ubuntu 10.04 Lucid Lynx

    Re: Simple Arithmetic Program (help pls)

    I don't follow all your requirements, but bash can do simple integer arithmetic either on variables or constants, by enclosing in double parentheses. For example,
    $ echo $((2+2))
    $ A=2
    $ B=3
    $ echo $((A+B))
    For reading input from a user, there is the bash builtin "read"
    type "help read|less" (without quotes) in a terminal for usage
    There are no dumb questions, just dumb answers.

  3. #3
    Join Date
    Sep 2009
    Ubuntu 12.10 Quantal Quetzal

    Re: Simple Arithmetic Program (help pls)

    I don't really understand what you want to do but maybe this helps:

    To add unit of times you can use date, but the format has to be HhourMminSsec:

    $ date --date '1/1 05hour20min10sec 10hour00min10sec' +%H:%M:%S
    The 1/1 makes date adding the values to Do 1. Jan 00:00:00

    To convert a unit of time into an integer use the epoch time:

    $ date --date '1/1 15:20:20' +%s
    ClassicMenu Indicator - classic GNOME menu for Unity
    Unsettings - configuration program for the Unity
    Privacy Indicator - easily switch privacy settings in Unity
    Arronax - create and modify app starters


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts