Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

OK, so it's not terribly unique, but I thought it was a bit of fun. The background (and the explanation of some odd bits) is at my personal blog. I wrote this because I was curious about my weight on the new Earth which was discovered. The program takes your current weight (in any units) as an argument. Defaults to my weight :)

#!/usr/bin/perl use strict; use warnings; my $weight = shift || 189; # you can manually change the weight here, + if you prefer # for simplicity's sake, we assume Audrey and Johnny are spherical my @data = ( # body mass in kg radius in km [ 'Mercury', 3.302 * 10**23, 2439.7 ], [ 'Venus', 4.8685 * 10**24, 6051.9 ], [ 'Earth', 5.9736 * 10**24, 6378.137 ], [ 'Moon', 7.3477 * 10**22, 1748.14 ], [ 'Mars', 6.4185 * 10**23, 3402.5 ], [ 'Ceres', 9.46 * 10**20, 950 ], # rough es +timates [ 'Jupiter', 1.8986 * 10**27, 71492 ], [ 'Saturn', 5.6846 * 10**26, 60286 ], [ 'Uranus', 8.6832 * 10**25, 25559 ], [ 'Neptune', 10.243 * 10**25, 24764 ], [ 'Pluto', 1.305 * 10**22, 1195 ], # rough es +timates [ 'Eris', 1.6 * 10**22, 1200 ], # rough es +timates [ 'Audrey Hepburn', 49.8951607, 0.0017018 ], [ 'Johnny Depp', 70.3068174, 0.001778 ], ); my ( %mass_of, %radius_of ); foreach my $data (@data) { my $body = $data->[0]; $mass_of{$body} = $data->[1]; $radius_of{$body} = $data->[2]; } $mass_of{Hope} = 5 * $mass_of{Earth}; $radius_of{Hope} = 1.5 * $radius_of{Earth}; $mass_of{'Heavy Earth'} = 2 * $mass_of{Earth}; $radius_of{'Heavy Earth'} = $radius_of{Earth}; $mass_of{'Fat Earth'} = $mass_of{Earth}; $radius_of{'Fat Earth'} = 2 * $radius_of{Earth}; print "If you weighed $weight units ...\n"; foreach my $body ( map( { $_->[0] } @data ), 'Hope', 'Heavy Earth', 'F +at Earth' ) { printf "... you would weigh %.2f units on '$body'\n" => weight_on( +$body); } sub weight_on { my $body = shift; return $weight * ( gravity($body) / gravity('Earth') ); } sub gravity { my $body = shift; return density($body) * $radius_of{$body}; } sub density { my $body = shift; return $mass_of{$body} / $radius_of{$body}**3; }

Cheers,
Ovid

New address of my CGI Course.


In reply to Calculate Your Weight On Various Heavenly Bodies by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (None)
    As of 2024-04-25 01:21 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found