Last active
August 29, 2015 13:57
-
-
Save dmakhmutov/9856329 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Enumerable | |
def cluster | |
cluster = [] | |
each do |element| | |
cluster.last && cluster.last.last == element ? cluster.last << element : cluster << [element] | |
end | |
cluster | |
end | |
end | |
class Sequence | |
include Enumerable | |
def initialize(arg) | |
@arg = arg | |
end | |
def to_s | |
@arg.to_s | |
end | |
def next | |
total = [] | |
@arg = @arg.to_s.split('') | |
@arg.cluster.map{ |x| total << x.uniq.unshift(x.size) } | |
@arg = total.flatten!.join.to_i | |
self | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment