Created
June 29, 2015 17:46
-
-
Save JFFail/4f837f51bf33fd50841b to your computer and use it in GitHub Desktop.
Solution to Reddit Daily Programmer #221 - Word Snake
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
#!/usr/bin/env ruby | |
#input = "SHENANIGANS SALTY YOUNGSTER ROUND DOUBLET TERABYTE ESSENCE" | |
input = "DELOREAN NEUTER RAMSHACKLE EAR RUMP PALINDROME EXEMPLARY YARD" | |
input = input.split(" ") | |
spaces = 0 | |
#Loop through the words. | |
input.each_with_index do |word, counter| | |
if counter % 2 == 0 | |
print " " * spaces | |
puts word | |
spaces += word.length - 1 | |
else | |
#To print down need an array of characters. | |
char_array = word.split("") | |
#Now loop through it and print. | |
char_array.each do |letter| | |
print " " * spaces | |
puts letter | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment