Hailstone sequence: Difference between revisions

Content added Content deleted
(Add CLU)
m (→‎{{header|R}}: Syntax highlighting.)
Line 8,201: Line 8,201:
=={{header|R}}==
=={{header|R}}==
===Iterative solution===
===Iterative solution===
<lang r>### PART 1:
<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 r>###Task 1:
<lang rsplus>###Task 1:
collatz<-function(n)
collatz<-function(n)
{
{