Time to flex those Golf skills.
Soccer leagues are often listed by points earned and games played. A team earns 3 points for a win and 1 point
for a tie. Zero points are earned for a loss.
The challenge is to create a function that gets two scalars, gamesPlayed
and pointsEarned and returns three scalars, winTotal, lossTotal, and tieTotal.
For this golf, ignore the possibility that the team may have more than 2 ties.
A non-golfed example is presented to give you somewhere to start.
sub record {
my ($gp, $pts) = @_;
my $win = 3;
my $tie = 1;
my ($winTot, $lossTot, $tieTot);
$winTot = int ($pts / $win);
$tieTot = $pts - ( $winTot * $win );
$lossTot = $gp - ( $winTot + $tieTot);
return ($winTot, $lossTot, $tieTot);
}
-
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.
|