Last active
June 22, 2019 18:06
-
-
Save sj26/4499379 to your computer and use it in GitHub Desktop.
Morse code translator in 1 line of ruby.
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
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