Skip to content

Instantly share code, notes, and snippets.

@llacroix
Created August 20, 2014 09:53
Show Gist options
  • Save llacroix/270a1a41766b8a0d55dc to your computer and use it in GitHub Desktop.
Save llacroix/270a1a41766b8a0d55dc to your computer and use it in GitHub Desktop.
Number serie
def split_num(arr)
arr.split("").map {|c|
c.to_i
}
.inject([]){|accumulator, value|
# puts "[#{accumulator}, #{value}]"
if accumulator.size > 0 and accumulator[-1][0] == value
accumulator[-1][1] += 1
else
accumulator.push([value, 1])
end
accumulator
}
.map {|value|
"#{value[1]}#{value[0]}"
}
.join("")
end
def loop (steps, init)
steps.times.inject([init]) {|c, r|
c.push(split_num(c[-1]))
}
end
puts loop(10, "1")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment