Skip to content

Instantly share code, notes, and snippets.

@sj26
Last active June 22, 2019 18:06
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sj26/4499379 to your computer and use it in GitHub Desktop.
Save sj26/4499379 to your computer and use it in GitHub Desktop.
Morse code translator in 1 line of ruby.
ARGF.each_line { |line| puts line.chomp.upcase.gsub(//, " ").gsub(/[^A-Z0-9:;=+_"$@ -]/, "-").gsub(/[A-Z0-9:;=+_"$@-]/, Hash[*%w(A .- B -... C -.-. D -.. E . F ..-. G --. H .... I .. J .--- K -.- L .-.. M -- N -. O --- P .--. Q --.- R .-. S ... T - U ..- V ...- W .-- X -..- Y -.-- Z --.. . .-.-.- , --..-- ? ..--.. / -..-. @ .--.-. 1 .---- 2 ..--- 3 ...-- 4 ....- 5 ..... 6 -.... 7 --... 8 ---.. 9 ----. 0 ----- : ---... ; -.-.-. = -...- + .-.-. - -....- _ ..--.- " .-..-. $ ...-..- @ .--.-.)]).strip }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment