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: | Line 8,201: | ||
=={{header|R}}== |
=={{header|R}}== |
||
===Iterative solution=== |
===Iterative solution=== |
||
<lang |
<lang rsplus>### PART 1: |
||
makeHailstone <- function(n){ |
makeHailstone <- function(n){ |
||
hseq <- n |
hseq <- n |
||
Line 8,254: | Line 8,254: | ||
===Vectorization solution=== |
===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: |
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 |
<lang rsplus>###Task 1: |
||
collatz<-function(n) |
collatz<-function(n) |
||
{ |
{ |