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))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue