http://qs1969.pair.com?node_id=24194


in reply to Generating a Pattern

Here's my version:
@a = (1); for (1..10) { print "@a\n"; @na=(); for (@a) { $na[-1] == $_ ? $na[-2]++ : push @na, (1, $_) } @a=@na; }
It does not move elements around (assuming push/pop are doing the natural thing) and has only one temporary copy.

Update: Use [-1] instead of [$#na]. Cool, learned a new thing!
Update: use ?: instead of if/then