Skip to content

Instantly share code, notes, and snippets.

@trejo08
Last active January 10, 2026 14:24
Show Gist options
  • Select an option

  • Save trejo08/8b63905e24297482f1149861479aa068 to your computer and use it in GitHub Desktop.

Select an option

Save trejo08/8b63905e24297482f1149861479aa068 to your computer and use it in GitHub Desktop.
Morse Code translator written in Ruby as solution of CodementorX Assessment.
class Morse
def posibilities(signals)
signals.include?('?') ? check_wildcard(signals) : morses["#{signals}"]
end
def check_wildcard(signals)
length = signals.split('').length
values = []
if length.eql?(1)
values = ["E", "T"]
else
indexes = []
chars = signals.split('')
chars.each.with_index do |char, index|
next if char.eql?('?')
indexes << index
end
morses.keys.each do |morse|
next unless morse.length.eql?(length)
valid = true
indexes.each do |index|
next if chars[index].eql?(morse.split('')[index])
valid = false
end
values << morses[morse] if valid
end
end
values
end
def morses
{
'.' => 'E',
'-' => 'T',
'..' => 'I',
'.-' => 'A',
'-.' => 'N',
'--' => 'M',
'...' => 'S',
'..-' => 'U',
'.-.' => 'R',
'.--' => 'W',
'-..' => 'D',
'-.-' => 'K',
'--.' => 'G',
'---' => 'O'
}
end
end
@jaindeen4
Copy link

jaindeen4 commented Jan 7, 2026

That’s a nice and practical choice for an assessment—building a Morse code translator really shows how you think about logic and edge cases. Writing it in Ruby keeps the solution clean and readable, which is great for reviewers. I like to think of a Morse code translator as decoding human signals, turning dots and dashes into meaningful text. For CodementorX, it’s a solid way to demonstrate problem-solving, mapping structures, and clear implementation. You can view more here themorsecodetranslator.net

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment