Proklet bio...
Kôd:
dict = [
'hello',
'there',
'yello',
'bob',
'tom',
'mabel',
'says',
'hi',
'secret',
'the',
'is',
'to',
'smile',
]
secrets = [
'45161 01223',
'x2x 3453 6k',
'x8z yz67zx 5y x4 y352z',
]
p Hash[secrets.map{|secret|
words = secret.split ' '
[secret, dict.permutation(words.length).find{|perm|
next unless perm.map(&:length) == words.map(&:length)
match = [words, perm]
chars = match.map{|e| e.join.chars.to_a}
next unless chars.map{|e| e.uniq.length}.inject(&:==)
pairs = chars.inject(&:zip)
Hash[pairs] == Hash[pairs.map(&:reverse)].invert
}.join(' ')]
}]
#=> {"45161 01223"=>"there yello", "x2x 3453 6k"=>"bob says hi", "x8z yz67zx 5y x4 y352z"=>"the secret is to smile"}
Mora da može i prostije...