Here's my solution. Is this the kind of thing you had in mind?
#! /usr/bin/perl
use strict;
use warnings;
my @left;
my @right;
for (my $i = 0; $i <= 11; $i++) {
my $j = $i+1;
$j = 0 if $j == 12;
print "Weigh Balls $i and $j\n";
print "Enter a result for each ball as follows:\n";
print " b-b Both balls balance\n";
print " u-d Left side up, right side down\n";
print " d-u Left side down, right side up\n";
chomp( my $input = <STDIN>);
my @results = split/-/, $input;
$left[$i] = $results[0];
$right[$j] = $results[1];
}
for (my $i = 0; $i <= 11; $i++) {
if (( $left[$i] eq "b") ||
( $right[$i] eq "b")) {
print "Ball $i is normal\n\n";
} elsif (( $left[$i] eq "d" ) &&
( $right[$i] eq "d")) {
print "Ball $i is Heavy!\n\n"
} elsif (( $left[$i] eq "u" ) &&
( $right[$i] eq "u" )) {
print "Ball $i is Light!\n\n";
} else {
print "Something is FUBAR somewhere!\n";
}
}
I haven't included any error checking for input errors, etc. It's just the bare logic.
Jack
-
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.
|