Skip to content

Instantly share code, notes, and snippets.

@mkweick
Last active November 26, 2015 17:18
Show Gist options
  • Save mkweick/22115ebe200c23b4e31d to your computer and use it in GitHub Desktop.
Save mkweick/22115ebe200c23b4e31d to your computer and use it in GitHub Desktop.
Series
class Series
attr_reader :series
def initialize(series)
@series = series
end
def slices(slice)
valid?(slice)
last_valid_index = series.length - slice
final_combos = []
series.each_char.with_index do |char, index|
if index <= last_valid_index
combination = []
n = 0
while n < slice do
combination << series[index + n].to_i
n += 1
end
final_combos << combination
end
end
final_combos
end
private
def valid?(slice)
fail ArgumentError if series.length - slice < 0
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment