Sha256: 20feddb16a96c1f8d4a42380f53235c8381b41b7847b8aae80ee0bfed54f144a

Contents?: true

Size: 1.17 KB

Versions: 73

Compression:

Stored size: 1.17 KB

Contents

package House;

use strict;
use warnings;

sub new {
    my $class = shift;
    return bless {}, $class;
}

sub recite {
    my $self = shift;
    my @rhyme;
    my @lines = (
        ['the house that Jack built.'],
        ['the malt', 'that lay in'],
        ['the rat', 'that ate'],
        ['the cat', 'that killed'],
        ['the dog', 'that worried'],
        ['the cow with the crumpled horn', 'that tossed'],
        ['the maiden all forlorn', 'that milked'],
        ['the man all tattered and torn', 'that kissed'],
        ['the priest all shaven and shorn', 'that married'],
        ['the rooster that crowed in the morn', 'that woke'],
        ['the farmer sowing his corn', 'that kept'],
        ['the horse and the hound and the horn', 'that belonged to'],
    );

    my @repeat;

    foreach my $i (0..$#lines) {
        my $block = "This is $lines[$i]->[0]\n";
        my $j     = $i - 1;
        my $that  = $lines[$i]->[1];

        while ($j >= 0) {
            $block .= "$that $repeat[$j]->[0]\n";
            $that   = $repeat[$j]->[1];
            $j--;
        }

        push @repeat, $lines[$i];
        push @rhyme,  $block;
    }

    return join "\n", @rhyme;
}

1;

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
trackler-2.2.1.159 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.158 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.157 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.156 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.155 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.154 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.153 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.152 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.151 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.150 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.149 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.148 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.147 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.146 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.145 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.144 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.143 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.142 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.141 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.140 tracks/perl5/exercises/house/.meta/solutions/House.pm