(Haskell) cf. Josh Triplett's program for
A005051.
import Data.List (group)
a001140 n = a001140_list !! (n-1)
a001140_list = 4 : map say a001140_list where
say = read . concatMap saygroup . group . show
where saygroup s = (show $ length s) ++ [head s]
(Perl)
# This outputs the first n elements of the sequence, where n is given on the command line.
$s = 4;
for (2..shift @ARGV) {
print "$s, ";
$s =~ s/(.)\1*/(length $&).$1/eg;
}
print "$s\n";
## Arne 'Timwi' Heizmann (timwi(AT)gmx.net), Mar 12 2008