Inspired by the Morse code question, and the Twinkle Twinkle little star question, write a program to accept a letter and generate the morse code audio for that letter.
Windows PowerShell, 200Makes a dot 70 ms long. Accordingly, a dash is 210 ms and the gap between both is 70 ms as well.
Since this contains control characters, here's a hexdump:
I have tried several variants pf packing the data more tightly, but PowerShell is quite verbose in unpacking them again, so I don't gain much, sadly. |
||||
|
|
QBASIC (236 characters)I count each newline as one character because QBasic seems to work fine without carriage returns, at least when running in DOSBox. Note that it only supports letters, not digits or punctuation.
|
|||||
|
JScript .NET (174 characters)A little-known programming language from Microsoft, it combines the (relative) terseness of JavaScript with the power of the .NET Common Language Runtime. Thanks minitech and Joey for Console.Beep. This program accepts a single letter from standard input (A-Z or a-z only). It does not explicitly add intra-character pauses, but they do exist, at least on Windows 7. morse.js
Compile with:
ExplanationSix 32-bit integers, of which 26 bits are used in each, serve as lookup tables. Each bit in a table corresponds to a letter of the alphabet, bit 25 used for A and bit 0 used for Z.
Because Morse code is a variable-length code that uses between 1 and 4 symbols for each letter, the tables 31313855 (bit 1) and 60257815 (bit 0) can together represent one less than the length of each letter's code.
The program uses additional lookup tables to store the dots and dashes for each letter. Using logic expressions of A and B, it stops once it has sent the correct number of symbols to the sound card.
In each of the four lookup tables above, a zero represents a dot; a one represents a dash.
|
||||
|
|
|
Sure. VB.NET,
|
|
The task says »Write a program ...«. I only see a few statements that won't compile on their own. Adding the module and sub declarations brings this to 272. – Joey May 20 '11 at 0:10 |
||
|
Who cares? Those are an unfair handicap and add absolutely nothing to the functionality of the program. I believe (as is noted in all of my questions here on Code Golf/Challenges) that default language structure should be able to be omitted from submissions to level the playing field. If you disagree, so be it. All I see here is over-sensitive nitpicking, and although nitpicking is great on programming forums, that kind of goes too far. – rynah May 20 '11 at 0:59 |
||
|
As for handicap and nitpicking: You may have your opinion there, but unless a task specifically asks for a code snippet instead of a function or complete program then your answer is just wrong according to the task specification. It's fine when your own tasks use a different metric, but respect that not everyone else uses it for their tasks. There are languages that golf better than others. No handicap you use will change that; we've discussed that on Meta already a while ago. – Joey May 20 '11 at 1:17 |
||
@Joey: Using the Split() function would prevent me from saving a space after In so it comes to the same number of characters. Maybe it has been discussed on Meta, but really - this is the important part. – rynah May 20 '11 at 1:22 |
|||
|
Adding the extra boilerplate does add something to the functionality of the program: it adds the ability for people who don't know the language to test it without having to learn the syntax. – Peter Taylor May 20 '11 at 7:13 |
cw. Accepts a line from standard input. Before running, dosudo apt-get install cw. – PleaseStand May 21 '11 at 16:52