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.139 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.138 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.137 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.136 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.135 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.134 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.133 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.132 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.131 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.130 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.129 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.128 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.127 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.126 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.125 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.124 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.123 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.122 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.121 tracks/perl5/exercises/house/.meta/solutions/House.pm
trackler-2.2.1.120 tracks/perl5/exercises/house/.meta/solutions/House.pm