A little Morse Code decoder in D

Aug 21, 2013 23:19

A little Morse Code decoder in D language, adapted from here:
http://apfelmus.nfshost.com/articles/fun-with-morse-code.html

void main() {
import std.stdio, std.string, std.array, std.algorithm, std.conv;

"-- --- .-. ... . -.-. --- -.. ."
.split(" ")
.map!(w => w
.split
.map!(s => " ETIANMSURWDKGOHVF L PJBXCYZQ "
[reduce!q{2 * a + 1 + (b & 1)}(0, s)])
.text)
.join(" ")
.writeln;
}It prints: MORSE CODE
Previous post Next post
Up