Created
December 6, 2010 23:05
-
-
Save loganrosen/731170 to your computer and use it in GitHub Desktop.
AlphabetSnake
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
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