Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: (Golf) The Animal Game

by redsquirrel (Hermit)
on Jan 23, 2002 at 21:42 UTC ( #140952=note: print w/replies, xml ) Need Help??

in reply to (Golf) The Animal Game

This is my second attempt at Perl Golf. Although my score (281) sucks, I wanted to post my code because I had a hard enough time just getting it to work at all. :-) I know I could make my code more concise, but I've run out of time! I've got to actually get some work done today!

My free subs:

sub a { print shift; my $answer = <STDIN>; chomp $answer; return 1 if $answer =~ /y/i; return 0; } sub t { print "What is your animal?\n"; my $answer = <STDIN>; chomp $answer; return $answer; } sub i { my ($g, $u) = @_; print "What is a question that is true for $u, but false for $g?\n +"; my $answer = <STDIN>; return $answer; } sub w { print "Do you want to continue?\n"; my $answer = <STDIN>; chomp $answer; return 1 if $answer =~ /y/i; return 0; } sub g { my $animal = shift; print "Is your animal a"; print "n" if $animal =~ /^[aeiou]/; print " $animal?\n"; my $answer = <STDIN>; chomp $answer; return 1 if $answer =~ /y/i; return 0; }

My free initialization:

my @t = ( [ undef,undef, ['cat','giraffe',"Is your animal larger than a breadbox?\n"] ] );

And my long-winded (281) solution:

sub r{my$t=shift;my$x=a($t->[2][2]);$t->[$x]?r($t->[$x]):return $t->[2 +][$x]}sub n{my$t=shift;for(0,1){if($t->[2][$_]eq$b&&!$t->[$_]){$t->[$_]=[undef,u +ndef,[$b,$ a,$q]];return 1}last if$t->[$_]&&n($t->[$_])}}while(1){$b=r($t[0]);if( +!g($b)){$a =t();$q=i($b,$a);n($t[0])}last if!w()}

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2021-01-16 11:43 GMT
Find Nodes?
    Voting Booth?