September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
52
Task/Morse-code/Gambas/morse-code.gambas
Normal file
52
Task/Morse-code/Gambas/morse-code.gambas
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
'Requires component 'gb.sdl2.audio'
|
||||
|
||||
Public Sub Main()
|
||||
Dim sMessage As String = "Hello World"
|
||||
Dim sFile As String = File.Load("../morse.txt") 'Contains A,.- B,-... etc
|
||||
Dim sChar As New String[]
|
||||
Dim sMorse As New String[]
|
||||
Dim sOutPut As New String[]
|
||||
Dim sTemp As String
|
||||
Dim siCount, siLoop As Short
|
||||
Dim bTrigger As Boolean
|
||||
Dim fDelay As Float = 0.4
|
||||
|
||||
If Not Exist("/tmp/dot.ogg") Then Copy "../dot.ogg" To "/tmp/dot.ogg" 'Sounds downloaded from
|
||||
If Not Exist("/tmp/dash.ogg") Then Copy "../dash.ogg" To "/tmp/dash.ogg" 'https://en.wikipedia.org/wiki/Morse_code#Letters.2C_numbers.2C_punctuation.2C_prosigns_for_Morse_code_and_non-English_variants
|
||||
|
||||
For Each sTemp In Split(sFile, gb.NewLine)
|
||||
sChar.add(Split(Trim(sTemp))[0])
|
||||
sMorse.add(Split(Trim(sTemp))[1])
|
||||
Next
|
||||
|
||||
For siCount = 1 To Len(sMessage)
|
||||
For siLoop = 0 To sChar.Max
|
||||
If sChar[siLoop] = Mid(UCase(sMessage), siCount, 1) Then
|
||||
sOutPut.Add(sMorse[siLoop])
|
||||
bTrigger = True
|
||||
Break
|
||||
End If
|
||||
Next
|
||||
If bTrigger = False Then sOutPut.Add(" ")
|
||||
bTrigger = False
|
||||
Next
|
||||
|
||||
Print sOutPut.Join(" ")
|
||||
|
||||
For siCount = 0 To Len(sMessage) - 1
|
||||
For siLoop = 0 To Len(sOutPut[siCount]) - 1
|
||||
If Mid(sOutPut[siCount], siLoop + 1, 1) = "." Then
|
||||
Music.Load("/tmp/dot.ogg")
|
||||
Music.Play
|
||||
Wait fDelay
|
||||
Else If Mid(sOutPut[siCount], siLoop + 1, 1) = "-" Then
|
||||
Music.Load("/tmp/dash.ogg")
|
||||
Music.Play
|
||||
Wait fDelay
|
||||
Else
|
||||
Wait fDelay
|
||||
Endif
|
||||
Next
|
||||
Next
|
||||
|
||||
End
|
||||
|
|
@ -1,48 +1,49 @@
|
|||
import javax.sound.sampled.AudioFormat
|
||||
import javax.sound.sampled.AudioSystem
|
||||
|
||||
val morseCode = hashMapOf('a' to ".-", 'b' to "-...", 'c' to "-.-.",
|
||||
'd' to "-..", 'e' to ".", 'f' to "..-.",
|
||||
'g' to "--.", 'h' to "....", 'i' to "..",
|
||||
'j' to ".---", 'k' to "-.-", 'l' to ".-..",
|
||||
'm' to "--", 'n' to "-.", 'o' to "---",
|
||||
'p' to ".--.", 'q' to "--.-", 'r' to ".-.",
|
||||
's' to "...", 't' to "-", 'u' to "..-",
|
||||
'v' to "...-", 'w' to ".--", 'x' to "-..-",
|
||||
'y' to "-.--", 'z' to "--..",
|
||||
val morseCode = hashMapOf(
|
||||
'a' to ".-", 'b' to "-...", 'c' to "-.-.",
|
||||
'd' to "-..", 'e' to ".", 'f' to "..-.",
|
||||
'g' to "--.", 'h' to "....", 'i' to "..",
|
||||
'j' to ".---", 'k' to "-.-", 'l' to ".-..",
|
||||
'm' to "--", 'n' to "-.", 'o' to "---",
|
||||
'p' to ".--.", 'q' to "--.-", 'r' to ".-.",
|
||||
's' to "...", 't' to "-", 'u' to "..-",
|
||||
'v' to "...-", 'w' to ".--", 'x' to "-..-",
|
||||
'y' to "-.--", 'z' to "--..",
|
||||
|
||||
'0' to ".....", '1' to "-....", '2' to "--...",
|
||||
'3' to "---..", '4' to "----.", '5' to "-----",
|
||||
'6' to ".----", '7' to "..---", '8' to "...--",
|
||||
'9' to "....-",
|
||||
'0' to ".....", '1' to "-....", '2' to "--...",
|
||||
'3' to "---..", '4' to "----.", '5' to "-----",
|
||||
'6' to ".----", '7' to "..---", '8' to "...--",
|
||||
'9' to "....-",
|
||||
|
||||
' ' to "/", ',' to "--..--", '!' to "-.-.--",
|
||||
'"' to ".-..-.", '.' to ".-.-.-", '?' to "..--..",
|
||||
'\'' to ".----.", '/' to "-..-.", '-' to "-....-",
|
||||
'(' to "-.--.-", ')' to "-.--.-")
|
||||
' ' to "/", ',' to "--..--", '!' to "-.-.--",
|
||||
'"' to ".-..-.", '.' to ".-.-.-", '?' to "..--..",
|
||||
'\'' to ".----.", '/' to "-..-.", '-' to "-....-",
|
||||
'(' to "-.--.-", ')' to "-.--.-"
|
||||
)
|
||||
|
||||
val symbolDurationInMs = hashMapOf('.' to 200, '-' to 500, '/' to 1000)
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
args.forEach { playMorseCode(toMorseCode(it.toLowerCase())) }
|
||||
}
|
||||
|
||||
fun toMorseCode(message: String) = message.filter { morseCode.containsKey(it) }
|
||||
.fold("") { (acc, ch) -> acc + morseCode[ch]!! }
|
||||
.fold("") { acc, ch -> acc + morseCode[ch]!! }
|
||||
|
||||
fun playMorseCode(morseCode: String) = morseCode.forEach { symbol -> beep(symbolDurationInMs[symbol]!!) }
|
||||
|
||||
fun beep(durationInMs: Int) {
|
||||
val soundBuffer = ByteArray(durationInMs * 8)
|
||||
for ((i, elem) in soundBuffer.withIndices()) {
|
||||
for ((i, _) in soundBuffer.withIndex()) {
|
||||
soundBuffer[i] = (Math.sin(i / 8.0 * 2.0 * Math.PI) * 80.0).toByte()
|
||||
}
|
||||
|
||||
val audioFormat = AudioFormat(/*sampleRate*/ 8000F,
|
||||
/*sampleSizeInBits*/ 8,
|
||||
/*channels*/ 1,
|
||||
/*signed*/ true,
|
||||
/*bigEndian*/ false)
|
||||
val audioFormat = AudioFormat(
|
||||
/*sampleRate*/ 8000F,
|
||||
/*sampleSizeInBits*/ 8,
|
||||
/*channels*/ 1,
|
||||
/*signed*/ true,
|
||||
/*bigEndian*/ false
|
||||
)
|
||||
with (AudioSystem.getSourceDataLine(audioFormat)!!) {
|
||||
open(audioFormat)
|
||||
|
||||
|
|
@ -53,3 +54,9 @@ fun beep(durationInMs: Int) {
|
|||
close()
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
args.forEach {
|
||||
playMorseCode(toMorseCode(it.toLowerCase()))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
25
Task/Morse-code/Ol/morse-code.ol
Normal file
25
Task/Morse-code/Ol/morse-code.ol
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
(display "Please, enter the string in lower case bounded by \" sign: ")
|
||||
(lfor
|
||||
(list->ff '(
|
||||
(#\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 . "-----")
|
||||
(#\space . " ") (#\. . " ")))
|
||||
(str-iter (read))
|
||||
(lambda (codes char)
|
||||
(let ((out (getf codes char)))
|
||||
(if out (display out)))
|
||||
codes))
|
||||
|
||||
; ==> Please, enter the string in lower case bounded by " sign:
|
||||
; <== "hello world"
|
||||
; ==> ......-...-..--- .-----.-..-..-..
|
||||
|
|
@ -1 +1 @@
|
|||
Send-MorseCode -Message "S.O.S"
|
||||
Send-MorseCode -Message "S.O.S" -ShowCode
|
||||
|
|
|
|||
11
Task/Morse-code/Sed/morse-code-1.sed
Normal file
11
Task/Morse-code/Sed/morse-code-1.sed
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#!/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.*//
|
||||
2
Task/Morse-code/Sed/morse-code-2.sed
Normal file
2
Task/Morse-code/Sed/morse-code-2.sed
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$ echo hello world! | ./morse.sed
|
||||
.... . .-.. .-.. --- .-- --- .-. .-.. -.. !
|
||||
Loading…
Add table
Add a link
Reference in a new issue