Learning how arrays work made this a lot shorter than my earlier attempt. The 0..333 gives 501+newline with 1&2, so the requirement for generating up to 500 char long sequences is met.
#!perl push@@,($@=$ARGV[$_%2])x($@[$_]||$@)for 0..333;print@@[0..(pop)-1],$/ |
I know there is a way to make it shorter, but I can't make it work :-)
#!perl
$%=pop;for$%(0..$%){$,=$ARGV[$%%2];$_.=$,x(/.{$%}(.)/?$+:$,)}/.{$%}/;print$&.$/
|
Still room for improvement, but figuring out how to use the arrays at all made it a bit shorter.
#!perl
($s,$b,$t)=@ARGV;for$,(($s,$b)x$t){$_.=$,x(substr($_,$u++,1)||$,)}s/(.{$t}).*/$1\n/;print
|
This was finished after 4 hours of picking up perl for the first time (for the cantor-problem).
#!perl
for(($s,$b,$t)=@ARGV;$u<$t;$u++){$_.=$s x(substr($_,$u,1)||$s);($s,$b)=($b,$s)}s/(.{$t}).*/$1\n/;print
|