自我描述数列是这玩意儿
http://zh.wikipedia.org/wiki/%E5%A4%96%E8%A7%80%E6%95%B8%E5%88%97
= 1, 11, 21, 1211, 111221, 312211, 13112221, 1113213211 (说明见上)
[实作1]
LookSay[str_String] := StringJoin @@
StringCases[str, p : ((x_(*?DigitQ*)) .. ~~ (x_ | "")) :>
ToString@StringLength[p] <> StringTake[p, {1}]];
- -
NestList[LookSay, "1", 10]
=> {"1", "11", "21", "1211", "111221", "312211", "13112221",
"1113213211", "31131211131221", "13211311123113112211",
"11131221133112132113212221"}
- -
说明: 函数核心部分在于
StringCases[str, ((x_(*?DigitQ*)) .. ~~ (x_ | ""))]
它的作用是把 "11223aaaab" 拆成 {"11", "22", "3", "aaaa", "b"}
若把(*?DigitQ*)的注解拿掉,则忽略掉字母。
叫做核心因为string pattern我最不熟,这部分改了最久XD
其他部分只是在做 "111" -> "3个1" -> "31" 这件事而已,是个拼拼凑凑。
- * - *
ListPlot[Log[StringLength /@ NestList[LookSay, "1", 40]],
PlotLabel -> "Log[length[LS[n]]]"]
(*数列的长度依指数增长的图示,原理的说明见wiki跟下*)
http://www.njohnston.ca/2010/10/a-derivation-of-conways-degree-71-look-and-say-polynomial/