-
-
Save Griminy/15bf0c17a4f2c0794ba739c468db1604 to your computer and use it in GitHub Desktop.
is_in_dictionary.rb
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
#!/usr/bin/env ruby | |
dict = ENV.fetch('DICTIONARY', ["две", "сотни", "тысячи"]) | |
string = ENV.fetch('WORD', "двесотни") | |
def in_dictionary?(dictionary:, string:) | |
formatted_string = string.gsub(/\s/, '') | |
squashed_dictionary = dictionary.flatten.each_with_object([]) do |i, res| | |
res << i.to_s unless i.nil? || i.empty? | |
end.uniq | |
squashed_dictionary.length.times do |i| | |
there_is_a_match = squashed_dictionary.permutation(i + 1).map(&:join).include?(string) | |
return true if there_is_a_match | |
end | |
false | |
end | |
puts in_dictionary?(dictionary: dict, string: string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment