Look-and-say sequence: Difference between revisions

Content added Content deleted
(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
Line 1,074: Line 1,074:
<syntaxhighlight lang="clojure">user> (take 8 (iterate look-and-say 1))
<syntaxhighlight lang="clojure">user> (take 8 (iterate look-and-say 1))
(1 11 21 1211 111221 312211 13112221 1113213211)</syntaxhighlight>
(1 11 21 1211 111221 312211 13112221 1113213211)</syntaxhighlight>

-----

The math above is lovely, Clojure using Java's regular expressions is also powerful:

<syntaxhighlight lang="clojure">(defn look-and-say
[n]
(->> (re-seq #"(.)\1*" n)
(mapcat (comp (juxt count first) first))
(apply str)))

(take 12 (iterate look-and-say "1"))</syntaxhighlight>

{{out}}

<syntaxhighlight lang="clojure">("1"
"11"
"21"
"1211"
"111221"
"312211"
"13112221"
"1113213211"
"31131211131221"
"13211311123113112211"
"11131221133112132113212221"
"3113112221232112111312211312113211")</syntaxhighlight>


=={{header|CLU}}==
=={{header|CLU}}==