Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Morse-code/Elixir/morse-code.elixir
Normal file
25
Task/Morse-code/Elixir/morse-code.elixir
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
defmodule Morse do
|
||||
@morse %{"!" => "---.", "\"" => ".-..-.", "$" => "...-..-", "'" => ".----.",
|
||||
"(" => "-.--.", ")" => "-.--.-", "+" => ".-.-.", "," => "--..--",
|
||||
"-" => "-....-", "." => ".-.-.-", "/" => "-..-.",
|
||||
"0" => "-----", "1" => ".----", "2" => "..---", "3" => "...--",
|
||||
"4" => "....-", "5" => ".....", "6" => "-....", "7" => "--...",
|
||||
"8" => "---..", "9" => "----.",
|
||||
":" => "---...", ";" => "-.-.-.", "=" => "-...-", "?" => "..--..",
|
||||
"@" => ".--.-.",
|
||||
"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" => "--..",
|
||||
"[" => "-.--.", "]" => "-.--.-", "_" => "..--.-" }
|
||||
def code(text) do
|
||||
String.upcase(text)
|
||||
|> String.codepoints
|
||||
|> Enum.map_join(" ", fn c -> Map.get(@morse, c, " ") end)
|
||||
end
|
||||
end
|
||||
|
||||
IO.puts Morse.code("Hello, World!")
|
||||
Loading…
Add table
Add a link
Reference in a new issue