blakew has asked for the wisdom of the Perl Monks concerning the following question:
Bit of silliness.
1. What's the next line?
1 1 1 2 1 1 2 1 1 1 1 1 2 2 1
2. Write code to print each line in the pattern (it gets unwieldy).
If the 5th line was 3 1 1 2 passing an argument gives that solution-
my $anchor = @ARGV ? '' : '^'; printf "%d\n", $_ = '1'; do { my $new; my ( $n ) = /^(\d)/o; while ( $_ ) { my $c = 0; $c++ while s/$anchor\s?$n\s?//; $new .= "$c $n " if $c; ( $n ) = /^(\d)/o; } print $_ = $new; } until ( <STDIN> =~ /\S/ );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: What's the answer to this puzzle? Most unique/golfed solution? (fun)
by thundergnat (Deacon) on Sep 23, 2011 at 02:09 UTC | |
by liverpole (Monsignor) on Sep 23, 2011 at 14:42 UTC | |
Re: What's the answer to this puzzle? Most unique/golfed solution? (fun)
by AnomalousMonk (Archbishop) on Sep 23, 2011 at 01:00 UTC | |
Re: What's the answer to this puzzle? Most unique/golfed solution? (fun)
by Anonymous Monk on Sep 24, 2011 at 04:06 UTC |
Back to
Seekers of Perl Wisdom