Writing Math Equations in PERL for HTML

Discussion in 'Perl Misc' started by cylurian@gmail.com, Feb 2, 2007.

  1. Guest

    Hello everyone. I create a lot of math questions with PERL and
    display them in html. One item that kills me is using negative signs,
    especially for displaying on html. Question is what is the best
    efficient way to account for positive and negative (addition and
    subtraction) signs when displaying in html? I write many conditional
    statements so I can account for the sign (operations). For example,
    lets say I have a quadratic: ax^2 + bc + c = 0

    And I want a, b and c to be random from -9 to -1 and 1 to 9. When I
    print the problem, I have to all the cases for displaying in html.

    If (($a >= 1)&&($b >= 1)&&($c >= 1) {

    print "$a x<sup>2</sup> + $b x + $c = 0";

    }elsif (($a >= 1)&&($b <= 1)&&($c >= 1)) {


    print "$a x<sup>2</sup> $b x + $c = 0";

    }..... keeps going until I cover all possible combinations with negative
    and positive signs. Any suggestions on being more efficient?
     
    , Feb 2, 2007
    #1
    1. Advertising

  2. On Feb 2, 10:15 pm, wrote:
    > Hello everyone. I create a lot of math questions with PERL and
    > display them in html. One item that kills me is using negative signs,
    > especially for displaying on html. Question is what is the best
    > efficient way to account for positive and negative (addition and
    > subtraction) signs when displaying in html? I write many conditional
    > statements so I can account for the sign (operations). For example,
    > lets say I have a quadratic: ax^2 + bc + c = 0
    >
    > And I want a, b and c to be random from -9 to -1 and 1 to 9. When I
    > print the problem, I have to all the cases for displaying in html.
    >
    > If (($a >= 1)&&($b >= 1)&&($c >= 1) {
    >
    > print "$a x<sup>2</sup> + $b x + $c = 0";
    >
    > }elsif (($a >= 1)&&($b <= 1)&&($c >= 1)) {
    >
    > print "$a x<sup>2</sup> $b x + $c = 0";
    >
    > }..... keeps going until I cover all possible combinations with negative
    >
    > and positive signs. Any suggestions on being more efficient?


    printf "%dx<sup>2</sup>%+dx%+d=0",$a,$b,$c;
     
    Brian McCauley, Feb 2, 2007
    #2
    1. Advertising

  3. Guest

    Wow, thanks. What can I do if $a = -1 and I want nothing to show, is
    there a faster way then doing a separte condition for $a like

    if ($a == -1) {
    printf "x<sup>2</sup>%+dx%+d=0",$a,$b,$c;
    }else {
    printf "%dx<sup>2</sup>%+dx%+d=0",$a,$b,$c;
    }


    On Feb 2, 2:27 pm, "Brian McCauley" <> wrote:
    > On Feb 2, 10:15 pm, wrote:
    >
    >
    >
    > > Hello everyone. I create a lot of math questions with PERL and
    > > display them in html. One item that kills me is using negative signs,
    > > especially for displaying on html. Question is what is the best
    > > efficient way to account for positive and negative (addition and
    > > subtraction) signs when displaying in html? I write many conditional
    > > statements so I can account for the sign (operations). For example,
    > > lets say I have a quadratic: ax^2 + bc + c = 0

    >
    > > And I want a, b and c to be random from -9 to -1 and 1 to 9. When I
    > > print the problem, I have to all the cases for displaying in html.

    >
    > > If (($a >= 1)&&($b >= 1)&&($c >= 1) {

    >
    > > print "$a x<sup>2</sup> + $b x + $c = 0";

    >
    > > }elsif (($a >= 1)&&($b <= 1)&&($c >= 1)) {

    >
    > > print "$a x<sup>2</sup> $b x + $c = 0";

    >
    > > }..... keeps going until I cover all possible combinations with negative

    >
    > > and positive signs. Any suggestions on being more efficient?

    >
    > printf "%dx<sup>2</sup>%+dx%+d=0",$a,$b,$c;
     
    , Feb 2, 2007
    #3
  4. Guest

    Wow, thanks. Is there a way for me to show only a negative for 1
    instead of -1. I know of two ways, but is there a better way.

    if ($a == -1 {

    $a = "-";
    }

    or

    if ($a == -1) {

    printf "-x<sup>2</sup>%+dx%+d=0", $b,$c;

    }else {

    printf "%dx<sup>2</sup>%+dx%+d=0",$a,$b,$c;

    }



    On Feb 2, 2:27 pm, "Brian McCauley" <> wrote:
    > On Feb 2, 10:15 pm, wrote:
    >
    >
    >
    > > Hello everyone. I create a lot of math questions with PERL and
    > > display them in html. One item that kills me is using negative signs,
    > > especially for displaying on html. Question is what is the best
    > > efficient way to account for positive and negative (addition and
    > > subtraction) signs when displaying in html? I write many conditional
    > > statements so I can account for the sign (operations). For example,
    > > lets say I have a quadratic: ax^2 + bc + c = 0

    >
    > > And I want a, b and c to be random from -9 to -1 and 1 to 9. When I
    > > print the problem, I have to all the cases for displaying in html.

    >
    > > If (($a >= 1)&&($b >= 1)&&($c >= 1) {

    >
    > > print "$a x<sup>2</sup> + $b x + $c = 0";

    >
    > > }elsif (($a >= 1)&&($b <= 1)&&($c >= 1)) {

    >
    > > print "$a x<sup>2</sup> $b x + $c = 0";

    >
    > > }..... keeps going until I cover all possible combinations with negative

    >
    > > and positive signs. Any suggestions on being more efficient?

    >
    > printf "%dx<sup>2</sup>%+dx%+d=0",$a,$b,$c;
     
    , Feb 2, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. chirs
    Replies:
    18
    Views:
    789
    Chris Uppal
    Mar 2, 2004
  2. AciD_X
    Replies:
    4
    Views:
    8,133
    Jonathan Turkanis
    Apr 1, 2004
  3. stacey
    Replies:
    6
    Views:
    399
    robert maas, see http://tinyurl.com/uh3t
    Feb 9, 2007
  4. Jeremy Watts

    math equations in java

    Jeremy Watts, May 21, 2008, in forum: Java
    Replies:
    17
    Views:
    2,613
    Andrew Thompson
    May 27, 2008
  5. VK
    Replies:
    15
    Views:
    1,218
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page