<?xml version="1.0" encoding="windows-1252"?>
<node id="140747" title="Re: (Golf) The Animal Game" created="2002-01-22 21:18:04" updated="2005-07-21 01:30:39">
<type id="11">
note</type>
<author id="85580">
dragonchild</author>
<data>
<field name="doctext">
I'll come in at 153 characters. I'm sure it has to be better than that ... I'm using too many temp vars.
&lt;p&gt;&lt;b&gt;Updated&lt;/b&gt;: Forgot to change my datastructure from a hash of hashes to a hash of arrays. That caused the bug [jarich] noticed. ++!
&lt;code&gt;
#!/usr/local/bin/perl

my %tree = (
    'larger than a breadbox' =&gt; [
        'cat',
        'giraffe',
    ],
);

sub a {
    print 'Is your animal ', shift, "?\n";
    my $answer = &lt;STDIN&gt;;
    chomp $answer;
    return 1 if $answer =~ /y/i;
    return 0;
}

sub t {
    print "What is your animal?\n";
    my $answer = &lt;STDIN&gt;;
    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 = &lt;STDIN&gt;;
    chomp $answer;
    $answer =~ s/Is your animal //;
    return $answer;
}

sub w {
    print "Do you want to continue?\n";
    my $answer = &lt;STDIN&gt;;
    chomp $answer;
    return 1 if $answer =~ /y/i;
    return 0;
}

#234567890#234567890#234567890#234567890#234567890#234567890#234567890#234567890
sub f {
($s,%t)=@_;$q=$s;do{{$v=a($q);$a=$t{$q}[$v];$q=$a,redo if$t{$a};$q=$s,next if a(
$a);$n=&amp;t;$o=i($a,$n);$t{$o}=[$t{$q}[$v],$n];$t{$q}[$v]=$o;$q=$s}}while&amp;w
}

f( 'larger than a breadbox',%tree);

__END__
&lt;/code&gt;
&lt;p&gt;------&lt;br&gt;&lt;i&gt;We are the carpenters and bricklayers of the Information Age.&lt;/i&gt;&lt;p&gt;Don't go borrowing trouble. For programmers, this means &lt;i&gt;Worry only about what you need to implement.&lt;/i&gt;</field>
<field name="root_node">
140734</field>
<field name="parent_node">
140734</field>
</data>
</node>
