Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
25
Task/Morse-code/EchoLisp/morse-code.echolisp
Normal file
25
Task/Morse-code/EchoLisp/morse-code.echolisp
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
(require 'json)
|
||||
(require 'hash)
|
||||
(require 'timer)
|
||||
|
||||
;; json table from RUBY
|
||||
(define morse-alphabet
|
||||
#'{"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":"--..","[":"-.--.","]":"-.--.-","_":"..--.-"," ":"|"}'#)
|
||||
|
||||
(define MORSE (json->hash (string->json morse-alphabet)))
|
||||
|
||||
;; translates a string into morse string
|
||||
;; use "|" as letters separator
|
||||
(define (string->morse str morse)
|
||||
(apply append (map string->list
|
||||
(for/list [(a (string-diacritics str))]
|
||||
(string-append
|
||||
(or (hash-ref morse (string-upcase a)) "?") "|")))))
|
||||
|
||||
(define (play-morse)
|
||||
(when EMIT ;; else return #f which stops (at-every)
|
||||
(case (first EMIT)
|
||||
((".") (play-sound 'digit) (write "dot"))
|
||||
(("-") (play-sound 'tick) (write "dash"))
|
||||
(else (writeln) (blink)))
|
||||
(set! EMIT (rest EMIT))))
|
||||
76
Task/Morse-code/FreeBASIC/morse-code.freebasic
Normal file
76
Task/Morse-code/FreeBASIC/morse-code.freebasic
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
' Using Beep function in Win32 API
|
||||
Dim As Any Ptr library = DyLibLoad("kernel32")
|
||||
Dim Shared beep_ As Function (ByVal As ULong, ByVal As ULong) As Long
|
||||
beep_ = DyLibSymbol(library, "Beep")
|
||||
|
||||
Sub playMorse(m As String)
|
||||
For i As Integer = 0 To Len(m) - 1
|
||||
If m[i] = 46 Then '' ascii code for dot
|
||||
beep_(1000, 250)
|
||||
Else '' must be ascii code for dash (45)
|
||||
beep_(1000, 750)
|
||||
End If
|
||||
Sleep 50
|
||||
Next
|
||||
Sleep 150
|
||||
End Sub
|
||||
|
||||
Dim morse(0 To 35) As String => _
|
||||
{ _
|
||||
".-", _ '' 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
|
||||
}
|
||||
|
||||
Dim s As String = "The quick brown fox"
|
||||
For i As Integer = 0 To Len(s) -1
|
||||
Select Case As Const s[i]
|
||||
Case 65 To 90 '' A - Z
|
||||
playMorse(morse(s[i] - 65))
|
||||
Case 97 To 122 '' a - z
|
||||
playMorse(morse(s[i] - 97))
|
||||
Case 48 To 57 '' 0 - 9
|
||||
playMorse(morse(s[i] - 22))
|
||||
Case Else
|
||||
'' ignore any other character
|
||||
Sleep 250
|
||||
End Select
|
||||
Next
|
||||
|
||||
DyLibFree(library)
|
||||
End
|
||||
97
Task/Morse-code/Phix/morse-code.phix
Normal file
97
Task/Morse-code/Phix/morse-code.phix
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
sequence morse = repeat(0,255)
|
||||
|
||||
procedure setMorse(sequence data)
|
||||
-- data is a list of strings, first char of each is the letter to encode,
|
||||
-- with the rest being the actual morse code for that letter, eg "S..."
|
||||
for i=1 to length(data) do
|
||||
morse[data[i][1]] = data[i][2..$] -- eg morse['S'] = "..."
|
||||
end for
|
||||
end procedure
|
||||
|
||||
setMorse({"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--..",
|
||||
"!-.-.--","\".-..-.","$...-..-",":---...",";-.-.-.","=-...-","?..--..","@.--.-.","_..--.-",
|
||||
"&.-...","'.----.","(-.--.",")-.--.-","+.-.-.",",--..--","--....-","..-.-.-","/-..-.",
|
||||
" "})
|
||||
|
||||
morse['a'..'z'] = morse['A'..'Z']
|
||||
morse['['] = morse['(']
|
||||
morse[']'] = morse[')']
|
||||
|
||||
constant EOM = ".-.-."
|
||||
|
||||
constant frequency = 1280, -- (in Hz, 37..32767)
|
||||
dit = 200, -- (in milliseconds)
|
||||
dah = 3*dit, -- ""
|
||||
lettergap = 2*dit/1000, -- (in seconds)
|
||||
wordgap = 4*dit/1000 -- ""
|
||||
|
||||
atom xBeep = 0
|
||||
|
||||
procedure beep(integer duration)
|
||||
if platform()=WIN32 then
|
||||
if xBeep=0 then
|
||||
atom kernel32 = open_dll("kernel32.dll")
|
||||
xBeep = define_c_proc(kernel32, "Beep", {C_INT,C_INT})
|
||||
end if
|
||||
c_proc(xBeep,{frequency,duration})
|
||||
end if
|
||||
end procedure
|
||||
|
||||
procedure playAndRebuild(string line)
|
||||
-- line should only contain '.'/'-'/' ', like the example below
|
||||
string rebuilt = ""
|
||||
integer start = 1
|
||||
integer ch
|
||||
if length(line)=0 then
|
||||
line = "... --- ... - .. - .- -. .. -.-. "
|
||||
puts(1,line)
|
||||
end if
|
||||
for i=1 to length(line) do
|
||||
ch = line[i]
|
||||
if ch=' ' then
|
||||
ch = find(line[start..i-1],morse)
|
||||
if ch!=0 then
|
||||
rebuilt &= ch
|
||||
start = i+1
|
||||
if ch=' ' then
|
||||
sleep(wordgap)
|
||||
else
|
||||
sleep(lettergap)
|
||||
end if
|
||||
end if
|
||||
elsif ch='.' then
|
||||
beep(dit)
|
||||
elsif ch='-' then
|
||||
beep(dah)
|
||||
end if
|
||||
end for
|
||||
puts(1,rebuilt)
|
||||
puts(1,"\n")
|
||||
end procedure
|
||||
|
||||
procedure main()
|
||||
integer key
|
||||
object code
|
||||
string line = ""
|
||||
|
||||
puts(1,"enter text, return to play/rebuild, escape to quit\n")
|
||||
while 1 do
|
||||
key = wait_key()
|
||||
if key = 27 then exit end if -- escape
|
||||
if key = 13 then -- return
|
||||
playAndRebuild(line)
|
||||
line = ""
|
||||
else
|
||||
code = morse[key]
|
||||
if string(code) then
|
||||
code &= ' '
|
||||
puts(1,code)
|
||||
line &= code
|
||||
end if
|
||||
end if
|
||||
end while
|
||||
puts(1,EOM)
|
||||
end procedure
|
||||
main()
|
||||
97
Task/Morse-code/Ursa/morse-code.ursa
Normal file
97
Task/Morse-code/Ursa/morse-code.ursa
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
decl ursa.util.sound snd
|
||||
decl string<> chars
|
||||
decl string<> morse
|
||||
|
||||
append "!" "\"" "$" "'" "(" ")" "+" chars
|
||||
append "---." ".-..-." "...-..-" ".----." "-.--." "-.--.-" ".-.-." morse
|
||||
append "," "-" "." "/" "0" "1" "2" chars
|
||||
append "--..--" "-....-" ".-.-.-" "-..-." "-----" ".----" "..---" morse
|
||||
append "3" "4" "5" "6" "7" "8" "9" chars
|
||||
append "...--" "....-" "....." "-...." "--..." "---.." "----." morse
|
||||
append ":" ";" "=" "?" "@" "A" "B" chars
|
||||
append "---..." "-.-.-." "-...-" "..--.." ".--.-." ".-" "-..." morse
|
||||
append "C" "D" "E" "F" "G" "H" "I" "J" "K" chars
|
||||
append "-.-." "-." "." "..-." "--." "...." ".." ".---" "-.-" morse
|
||||
append "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" chars
|
||||
append ".-.." "--" "-." "---" ".--." "--.-" ".-." "..." "-" "..-" morse
|
||||
append "V" "W" "X" "Y" "Z" "[" "]" "_" chars
|
||||
append "...-" ".--" "-..-" "-.--" "--.." "-.--." "-.--.-" "..--.-" morse
|
||||
|
||||
decl int e f chargap wordgap
|
||||
# element time in ms. one dot is on for e then off for e
|
||||
set e 50
|
||||
# tone frequency in hertz
|
||||
set f 1280
|
||||
# time between characters of a word (in units of e)
|
||||
set chargap 1
|
||||
# time between words (in units of e)
|
||||
set wordgap 7
|
||||
|
||||
|
||||
def gap (int n)
|
||||
sleep (* n e)
|
||||
end gap
|
||||
decl function off
|
||||
set off gap
|
||||
|
||||
|
||||
def on (int n)
|
||||
snd.beep f (/ (* n e) 1000)
|
||||
end on
|
||||
|
||||
|
||||
def dot ()
|
||||
on 1
|
||||
off 1
|
||||
end dot
|
||||
|
||||
|
||||
def dash ()
|
||||
on 3
|
||||
off 1
|
||||
end dash
|
||||
|
||||
|
||||
def bloop (int n)
|
||||
snd.beep (/ f 2) (/ (* n e) 1000)
|
||||
end bloop
|
||||
|
||||
|
||||
def encode_morse (string text)
|
||||
decl string<> words
|
||||
set words (split (upper (trim text)) " ")
|
||||
decl int i j k
|
||||
for () (< i (size words)) (inc i)
|
||||
for (set j 0) (< j (size words<i>)) (inc j)
|
||||
decl int loc
|
||||
set loc (locate words<i><j> chars)
|
||||
if (= loc -1)
|
||||
bloop 3
|
||||
else
|
||||
for (set k 0) (< k (size morse<loc>)) (inc k)
|
||||
if (= morse<loc><k> "-")
|
||||
dash
|
||||
elif (= morse<loc><k> ".")
|
||||
dot
|
||||
else
|
||||
bloop 3
|
||||
end if
|
||||
end for
|
||||
end if
|
||||
gap chargap
|
||||
end for
|
||||
gap wordgap
|
||||
end for
|
||||
end encode_morse
|
||||
|
||||
|
||||
# --- uncomment this block to output the source of this file as morse
|
||||
# decl file src
|
||||
# src.open args<0>
|
||||
# encode_morse (src.readall)
|
||||
|
||||
|
||||
while true
|
||||
out "A string to change into morse: " console
|
||||
encode_morse (in string console)
|
||||
end while
|
||||
Loading…
Add table
Add a link
Reference in a new issue