Morse Printer

Report a typo

Scally wants to play with Morse coding, so she started making a program for transforming numbers to dots and dashes. Can you help her complete the program? Note that we can print non-negative numbers only.

Sample Input 1:

0123456789

Sample Output 1:

_____.____..___...__...._....._....__...___..____.
Write a program in Scala 3
object MorsePrinter extends App {

val morseDigitsUntil5 = Map(
0 -> "_____",
1 -> ".____",
2 -> "..___",
3 -> "...__",
4 -> "...._",
5 -> "....."
)
val morseDigitsAfter5 = Map(
6 -> morseDigitsUntil5(4).reverse,
???
)
val morseDigits = ???

def build(source: String, result: List[String]): List[String] =
if (source.nonEmpty) {
val current = morseDigits((source.head - '0') % 10)
build(source.???, result :+ current)
} else result

val input = scala.io.StdIn.readLine()
println(build(input, List.empty).mkString)
}
___

Create a free account to access the full topic