How to resolve the algorithm Morse code step by step in the sed programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Morse code step by step in the sed programming language
Table of Contents
Problem Statement
Morse code is one of the simplest and most versatile methods of telecommunication in existence. It has been in use for more than 175 years — longer than any other electronic encoding system.
Send a string as audible Morse code to an audio device (e.g., the PC speaker).
As the standard Morse code does not contain all possible characters, you may either ignore unknown characters in the file, or indicate them somehow (e.g. with a different pitch).
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Morse code step by step in the sed programming language
Source code in the sed programming language
#!/bin/sed -rf
# Convert to uppercase
s/.*/\U&/
# Add lookup table
s/$/\nA.-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--../
# Main loop
:a
s/([A-Z])([^\n]*\n.*\1([-.]+))/\3 \2/
ta
# Remove lookup table
s/\n.*//
$ echo hello world! | ./morse.sed
.... . .-.. .-.. --- .-- --- .-. .-.. -.. !
You may also check:How to resolve the algorithm 99 bottles of beer step by step in the NASL programming language
You may also check:How to resolve the algorithm Split a character string based on change of character step by step in the Arturo programming language
You may also check:How to resolve the algorithm World Cup group stage step by step in the Elena programming language
You may also check:How to resolve the algorithm Greatest common divisor step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm FTP step by step in the Java programming language