Skip to content

Instantly share code, notes, and snippets.

@loganrosen
Created December 6, 2010 23:05
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 loganrosen/731170 to your computer and use it in GitHub Desktop.
Save loganrosen/731170 to your computer and use it in GitHub Desktop.
AlphabetSnake
alphabet = ("A".."Z").to_a
reversealphabet = alphabet.reverse
puts "Please enter the number of rows: "
rows = gets.chomp.to_i
puts "Please enter the number of columns: "
columns = gets.chomp.to_i
totalspaces = rows.to_i*columns.to_i
copyfactor = (totalspaces / 26) + 1
alphabetarray = alphabet*copyfactor
columnposition = 1
arrayspot = 0
rowposition = 1
while arrayspot < totalspaces
if columnposition<=columns
print (alphabetarray.at(arrayspot))
arrayspot = arrayspot+1
columnposition = columnposition+1
else
if rowposition%2 == 0
(alphabetarray.at(rows*(rowposition-1)+(columns-1))...alphabetarray.at(rows*(rowposition-1)+(columns-2+columns))).to_a.reverse
end
puts ""
columnposition = 1
rowposition = rowposition+1
end
end
#n = 0
#p=0
#currentrow = 1
#columnposition = 1
#while p<=(rows-1)
# while columnposition < columns
# if currentrow%2 != 0
# print(alphabet.at(n))
# if n>25
# n = 0
# n = n+1
# end
# else
# print(alphabet.reverse.at(n))
# n = n-1
# if n<(-25)
# n=25
# end
# end
# end
# puts "\n"
# currentrow = currentrow+1
# columnposition = columnposition + 1
# p = p+1
#end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment