Skip to content

Instantly share code, notes, and snippets.

@agnaite
Last active October 9, 2017 20:15
Show Gist options
  • Save agnaite/c0ed8b80ef23c05c6dab359987cbd988 to your computer and use it in GitHub Desktop.
Save agnaite/c0ed8b80ef23c05c6dab359987cbd988 to your computer and use it in GitHub Desktop.
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