Hailstone sequence: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add CLU) |
ReeceGoding (talk | contribs) m (→{{header|R}}: Syntax highlighting.) |
||
Line 8,201:
=={{header|R}}==
===Iterative solution===
<lang
makeHailstone <- function(n){
hseq <- n
Line 8,254:
===Vectorization solution===
The previous solution is entirely satisfactory and may be more efficient than the following solution. However, problems like these are a great chance to show off the strength of R's vectorization. Also, this lets us show off how the <- syntax can do multiple variable assignments in one line. Observe how short the following code is:
<lang
collatz<-function(n)
{
|