Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
28
Task/Morse-code/Scala/morse-code.scala
Normal file
28
Task/Morse-code/Scala/morse-code.scala
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
object MorseCode extends App {
|
||||
|
||||
private val code = Map(
|
||||
('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', "--.. "), ('0', "----- "), ('1', ".---- "),
|
||||
('2', "..--- "), ('3', "...-- "), ('4', "....- "), ('5', "..... "),
|
||||
('6', "-.... "), ('7', "--... "), ('8', "---.. "), ('9', "----. "),
|
||||
('\'', ".----."), (':', "---... "), (',', "--..-- "), ('-', "-....- "),
|
||||
('(', "-.--.- "), ('.', ".-.-.- "), ('?', "..--.. "), (';', "-.-.-. "),
|
||||
('/', "-..-. "), ('-', "..--.- "), (')', "---.. "), ('=', "-...- "),
|
||||
('@', ".--.-. "), ('"', ".-..-. "), ('+', ".-.-. "), (' ', "/")) // cheat a little
|
||||
|
||||
private def printMorse(input: String): Unit = {
|
||||
println(input)
|
||||
println(input.trim.replaceAll("[ ]+", " ").toUpperCase
|
||||
.map(code.getOrElse(_, "").trim).mkString(" "))
|
||||
}
|
||||
|
||||
printMorse("sos")
|
||||
printMorse(" Hello World!")
|
||||
printMorse("Rosetta Code")
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue