Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
117 116 117. But with caveats.

The main caveat is that I can add or lose characters depending on exact behaviour of these additional functions. (Particularly important is the behaviour of "a". I assumed that it returned 0,1 and added returns on prints but not a ?.) Here are the exact functions as I used them for my solution:

sub a { print @_, "\n"; my $r = <STDIN>; if ($r =~ /y/i) { return 1; } elsif ($r =~ /n/i) { return 0; } else { print "Sorry, I don't understand that. Please answer Y/N.\n"; a(@_); } } sub t { print "What is your animal?\n"; my $ans = <STDIN>; chomp($ans); return $ans; } sub i { my ($guessed, $user_answer) = @_; chomp($guessed, $user_answer); print "Please enter a question that would be true for a " . "$user_answer, but false for a $guessed:\n"; my $ans = <STDIN>; chomp($ans); return $ans; } sub w { if (a("\nDo you want to continue?")) { print "\nStarting a new game.\n"; } else { print "BYE!\n"; exit(); } }
Add to that my one free initialization:
$Q{a}="golfer";
And then my solution:
# 1 2 3 4 5 6 +7 8 9 10 11 #123456789_123456789_123456789_123456789_123456789_123456789_123456789 +_123456789_123456789_123456789_123456789_1234567 {*q=\%Q;*q=$q{a$q{q}}while$q{q};$q{0}{a}=$q{a},$q{1}{a}=t,$q{q}=i($q{a +},$q{1}{a})if!a"Is your animal a $q{a}?";w,redo} # Was #{*q=*Q;*q=$q{a$q{q}}while$q{q};$q{0}{a}=$q{a},$q{1}{a}=t,$q{q}=i($q{a +},$q{1}{a})if!a"Is your animal a $q{a}?";w&&redo}
UPDATE
jarich is right, I forgot to test something. My first typeglob assignment was wrong

In reply to Re (tilly) 1: (Golf) The Animal Game by tilly
in thread (Golf) The Animal Game by Masem

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 having an uproarious good time at the Monastery: (5)
As of 2024-03-28 14:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found