Created
October 24, 2013 16:28
-
-
Save RudolfHattenkofer/7140398 to your computer and use it in GitHub Desktop.
Generate a never ending list of words.
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
# Initialize variables | |
alphabet = 1 | |
word = 1 | |
direction = 'down' | |
ignore = false | |
chars = [] | |
# 0..20 is just a soft limit so the machine doesn't crash. Switch the hashtag | |
# in front of the following two lines for endless mode: | |
# while true # Remove the first hashtag here | |
(0..20).each do |i| # Add the hashtag in this line | |
# Generate char list for this step | |
chars = [] | |
(1..alphabet).each do |char| | |
chars << (64 + char).chr | |
end | |
# Generate word list | |
word_list = chars.repeated_permutation(word).to_a.map do |word| | |
puts word.join('') | |
end | |
# Maybe jump over the border detection | |
if ignore | |
# Don't jump in the next step | |
ignore = false | |
else | |
# If we are at the left border, go down and then go right up in the next step | |
if alphabet == 1 | |
direction = 'up' | |
word += 1 | |
ignore = true | |
next | |
# If we are at the top border, go right and then down left in the next step | |
elsif word == 1 | |
direction = 'down' | |
alphabet += 1 | |
ignore = true | |
next | |
end | |
end | |
# Go right up or down right in the table | |
# => Calculate the next alphabet and word length | |
if direction == 'down' | |
word += 1 | |
alphabet -= 1 | |
elsif direction == 'up' | |
word -= 1 | |
alphabet += 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment