Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Odd Ball Challenge

by jcoxen (Deacon)
on Jun 24, 2005 at 01:54 UTC ( [id://469587]=note: print w/replies, xml ) Need Help??


in reply to Odd Ball Challenge

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

Replies are listed 'Best First'.
Re^2: Odd Ball Challenge
by Limbic~Region (Chancellor) on Jun 24, 2005 at 12:37 UTC
    jcoxen,
    Here's my solution. Is this the kind of thing you had in mind?

    Not what I had in mind. See my response to kaif for details. The challenge is to write a solution-generator. For a previous example of such a challenge - see Challenge: Setting Sun Puzzle

    Cheers - L~R

      Yeah, I've been following the thread and had figured out on my own that I was off base.

      Interesting puzzle. I can figure out a solution but trying to duplicate the steps my brain took to solve this and then translating those steps into Perl is beyond me. Actually, trying to figure out how (or if) my brain works is more than enough challenge for anyone.

      Anyway, I'll be interested to find out if anyone manages to solve this one - and if their program comes up with the same solution I did.

      Jack

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2024-04-19 07:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found