2010-11-11, 08:02 PM
In R.
This solves the more complicated version because the shorter one is the same number of characters, just change the first line into 2 lines:
135 characters either way, if I counted right.
I'm slightly cheating because to put in more than 1 digit, you use morris(c(1,3,1,3,1,3)), not morris(131313).
Also, technically speaking, it'll overflow when R runs out of memory (in 32-bit R, after 3 gigs, in 64-bit, after it uses all your RAM). But not much I can do about that.
Code:
morris <- function(b=1) {
c = b
repeat {
cat(b,"\n",sep="")
n = -1
x = n
for (i in 1:length(b)) {
if (b[i]==x) c[n]=c[n]+1
else {
n=n+2
x=b[i]
c[n+1]=x
c[n]=1
}
}
b = c
}
}Code:
morris <- function() {
b=1135 characters either way, if I counted right.
I'm slightly cheating because to put in more than 1 digit, you use morris(c(1,3,1,3,1,3)), not morris(131313).
Also, technically speaking, it'll overflow when R runs out of memory (in 32-bit R, after 3 gigs, in 64-bit, after it uses all your RAM). But not much I can do about that.
Version that will take integer input as specified: 183 chars

