Prompted by a student project, I started looking into R today. Well, this is what the usual Hailstone program looks like in R:
hailstone <- function(n)
  while (print(n) > 1) 
    n <- if (n %% 2 == 0) n / 2 else 3 * n + 1; 
I started writing it in a very C-like way, but the functional nature of the language made itself increasingly more apparent as I played around with the code.

No comments: