Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

RE: Adding 2 + 2

by KM (Priest)
on Sep 11, 2000 at 19:01 UTC ( #31891=note: print w/ replies, xml ) Need Help??


in reply to Adding 2 + 2

Ok, this is fun :)

perl -MFcntl=:flock -e 'print 2+LOCK_EX'

Or (cheap way)

perl -wle 'print $^W*2**$^W*2'

Or (Only works if you follow the directions ;-)

#!/usr/bin/perl -w use strict; print "Pick an integer between 1 and 3\n"; my $num = <STDIN>; print "Pick another integer between 1 and 3\n"; $num += <STDIN>; print "The sum is " . $num;

Or

perl -wle '%h = map {(qq{sum}) => $h{'sum'}+=$_ } qw/2 2/; print $h{s +um}'

Or (a long version of the above one liner)

#!/usr/bin/perl -w use strict; my %foo; %foo = map {('sum') => $foo{'sum'}+=$_ } qw/2 2/; print $foo{sum};

More later if I have time.

Cheers,
KM


Comment on RE: Adding 2 + 2
Select or Download Code
Replies are listed 'Best First'.
RE (tilly) 2: Adding 2 + 2
by tilly (Archbishop) on Sep 11, 2000 at 19:18 UTC
    I follow the directions, but it tells me that the sum is 3. Did you mean to write directions that do not allow 1.5 as input?
      Haha.. I made the directions more clear.

      Cheers,
      KM

        Is that integer range "between 1 and 3" inclusive or exclusive? You might want to include some error-checking:
        { print "Pick an integer between 1 and 3 (exclusive):" $mynum1 = <STDIN>; (print "Follow instructions!\n"),redo unless ($mynum < 3) and ($mynum > 1) and ($mynum == int($mynum)); }
RE: RE: Adding 2 + 2
by Adam (Vicar) on Sep 11, 2000 at 20:29 UTC
    perl -wle 'print $^W*2**$^W*2'
    That's not 2 + 2, thats 2 squared.
    (Ok, I know... the answer is the same... but the route is different.)
      Well, speaking as a engineer by training, the program meets spec... where's the problem? <G>

      If you wanted flexibility and easy upgrades, you should have made sure that was part of the original program spec.

      Ozymandias pries tongue from cheek...

      - email Ozymandias
      Uh, I thought 2 squared was just a shorthand for 2 + 2, er, or inherently linked or something. Sure, it a ... what's that word, pathological? case but ...

      a

        So nearly...

        22 is a shorthand for 2x2, which is a special case, since the exponent equals the mantissa. It's only equal to 2+2 by coincidence, though, or rather, due to the fact that 2 enumerates the number of arguments taken by binary (!=base 2) addition. There's nothing terribly pathological about any of this. The result (which I understand Larry wants allowed by Perl 6) that 00=1 is really pathological.

        And I may be just a novice, but how about:
         sub addtwoandtwo { 2+2 } ?

        Tiefling (utter novice)

        Thanks for the downvotes! Feel like telling me what's wrong?
RE: RE: Adding 2 + 2
by BastardOperator (Monk) on Sep 11, 2000 at 19:09 UTC
    *bends down on knee*
    Will you marry me? ;)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://31891]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (13)
As of 2015-07-29 21:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls