Last active
August 29, 2015 14:26
-
-
Save ericwo/86dfb24af83564f02509 to your computer and use it in GitHub Desktop.
The Telegram Problem
This file contains 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
class Telegram | |
attr_reader :elements | |
def initialize file | |
context = File.open(file).read | |
context.gsub!("\n", ' ') | |
@elements = context.split(' ') | |
end | |
def container | |
return false if @elements.length <= 0 | |
length = 30 | |
temp_array = [] | |
@elements.each do |element| | |
if element.length < length | |
print "#{element} " | |
temp_array.push element | |
length = length - element.length - 1 | |
else | |
@elements = @elements - temp_array | |
print "\n" | |
return | |
end | |
end | |
@elements = @elements - temp_array | |
end | |
def printer | |
while @elements.length > 0 | |
container | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment