Skip to content

Instantly share code, notes, and snippets.

@dmakhmutov
Last active August 29, 2015 13:57
Show Gist options
  • Save dmakhmutov/9835395 to your computer and use it in GitHub Desktop.
Save dmakhmutov/9835395 to your computer and use it in GitHub Desktop.
module Enumerable
def cluster
cluster = []
each do |element|
if cluster.last && cluster.last.last == element
cluster.last << element
else
cluster << [element]
end
end
cluster
end
end
class Sequence
include Enumerable
def initialize(arg)
@arg = arg
end
def next
total,result = [], ""
@arg = @arg.to_s.split('')
@arg.cluster.map{ |x| total << x.uniq.unshift(x.size) }
@arg = total.flatten!
@arg.each{|x| result += x.to_s}
@arg = result.to_i
end
end
a = Sequence.new(1)
p a.next
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment