-
-
Save rklemme/1010337 to your computer and use it in GitHub Desktop.
(fork) I'm trying to split a phrase into 6 or less rows of 12 or less letters each.
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
LEN = 60 | |
LIMIT = 12 | |
phrase = nil | |
begin | |
puts "Enter phrase. #{LEN} characters or less." | |
phrase = gets.chomp | |
end while phrase.length > LEN | |
lines = [] | |
phrase.downcase.scan /[a-z]+/ do |word| | |
if lines.empty? || lines.last.length + 1 + word.length > LIMIT | |
lines << word.dup | |
else | |
lines.last << " " << word | |
end | |
end | |
puts lines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment