Skip to content

Instantly share code, notes, and snippets.

@moisesnandres
Created August 15, 2018 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moisesnandres/29314b9ea5235c002b2524efa1c103cd to your computer and use it in GitHub Desktop.
Save moisesnandres/29314b9ea5235c002b2524efa1c103cd to your computer and use it in GitHub Desktop.
def decode_message(input)
words = input.split("\n")
letters = [{}, {}, {}, {}, {}, {}]
words.each do |word|
word.each_char.with_index do |char, index|
if letters[index].key?(char)
letters[index][char] = letters[index][char] + 1
else
letters[index][char] = 1
end
end
end
letters.map { |letter| letter.key(letter.values.max).to_s }.join
end
decode_message('eedadn
drvtee
eandsr
raavrd
atevrs
tsrnev
sdttsa
rasrtv
nssdts
ntnada
svetve
tesnvt
vntsnd
vrdear
dvrsen
enarar')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment