Point-free look and say sequence
Haskell 206 Chars
import Data.List
import Control.Applicative
import Data.Function
main= readLn >>= print .(flip take (map read $ fix (("1":). map (concat .(map ((++)<$>(show . length)<*>((:[]). head))). group))::[Integer]))
It works by using the group function to group them into groups of equal things. Then it uses applicatives with functions to build a function that simultaneously reads the length, and appends it to with one the elements. It uses a fix and a map to create a recursive definition (point-free.) And there ya go.
J (42 chars)
Point-free (also called tacit) programming is natural in J.
,@:((#,{.);.1~(1,}.~:}:))&.>^:(<`((<1)"_))
That's a function, to use it you write the code, a space, and the input number. For example,
,@:((#,{.);.1~(1,}.~:}:))&.>^:(<`((<1)"_)) 8
┌─┬───┬───┬───────┬───────────┬───────────┬───────────────┬───────────────────┐
│1│1 1│2 1│1 2 1 1│1 1 1 2 2 1│3 1 2 2 1 1│1 3 1 1 2 2 2 1│1 1 1 3 2 1 3 2 1 1│
└─┴───┴───┴───────┴───────────┴───────────┴───────────────┴───────────────────┘
Notice the pretty boxes in the output.
Addendum: Here are a couple of "cheats" I was too bashful to use at first, but now that I've seen other use them first...
Here's a 36 char version with a different "calling convention": replace 8 with the number of terms you want.
,@:((#,{.);.1~(1,}.~:}:))&.>^:(<8)<1
And if having extra zeroes in the output is OK, here's a 32 char version:
,@:((#,{.);.1~(1,}.~:}:))^:(<8)1
Bash and coreutils, 111 73 chars
eval echo 1\|`yes 'tee -a o|fold -1|uniq -c|(tr -dc 0-9;echo)|'|sed $1q`:
uniq -c
is doing the heavy lifting to produce the next number in the sequence. yes
, sed
and eval
create the necessary number of repeats of the processing pipeline. The rest is just formatting.
Output is placed in a file called o
.:
$ ./looksay.sh 8 ubuntu@ubuntu:~$ cat o 1 11 21 1211 111221 312211 13112221 1113213211 $