Skip to content

Instantly share code, notes, and snippets.

@JFFail
Created June 29, 2015 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JFFail/4f837f51bf33fd50841b to your computer and use it in GitHub Desktop.
Save JFFail/4f837f51bf33fd50841b to your computer and use it in GitHub Desktop.
Solution to Reddit Daily Programmer #221 - Word Snake
#!/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