Skip to content

Instantly share code, notes, and snippets.

@coreyjs
Created July 25, 2020 15:37
Show Gist options
  • Select an option

  • Save coreyjs/6b4a5b35677cfc0b04b830e67065aba1 to your computer and use it in GitHub Desktop.

Select an option

Save coreyjs/6b4a5b35677cfc0b04b830e67065aba1 to your computer and use it in GitHub Desktop.
Hash all string permutations
hash = {}
0.upto(s1.length.to_i - 1).flat_map do |start|
1.upto(s1.length - start).map do |length|
hash[s1[start, length]] = length
end
end.uniq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment