Last active
October 9, 2017 20:15
-
-
Save agnaite/c0ed8b80ef23c05c6dab359987cbd988 to your computer and use it in GitHub Desktop.
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
def make_chains(words) | |
chains = {} | |
for i in 0..words.length-2 | |
word_1 = words[i] | |
word_2 = words[i + 1] | |
value = words[i + 2] | |
if !chains.include? word_1 | |
chains[word_1] = {} | |
end | |
if !chains[word_1].include? word_2 | |
chains[word_1][word_2] = [] | |
end | |
chains[word_1][word_2] << value | |
end | |
puts chains | |
chains | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment