Skip to main content
4 of 5
deleted 79 characters in body
Rick Hitchcock
  • 2.6k
  • 11
  • 17

#JavaScript (ES6), 170 135 bytes

s=>s.split`000`.map(e=>'  ETIANMSURWDKGOHVF L PJBXCYZQ'[c=parseInt(1+e.replace(/0?(111|1)/g,d=>+(d>1)),2)]||'473168290 5'[c%11]).join``

**How it works:**

If you change the dots to 0s and the dashes to 1s, and prefix with a 1, you get binary numbers, which when converted to decimal gives you:

  1. Letters: 2 - 18, 20, and 22 - 29.
    These can be converted to the correct letters by indexing into ' ETIANMSURWDKGOHVF L PJBXCYZQ'.
  2. Numbers: 32, 33, 35, 39, 47, 48, 56, 60, 62, and 63.
    If we take these numbers modulus 11, we get the numbers 0 - 8 and 10, which can be converted to the correct numbers by indexing into '473168290 5'.

The program splits on characters, then converts each character into dots and dashes, which are converted into the appropriate output based on the above rules.


Test Cases:

let f=

s=>s.split`000`.map(e=>'  ETIANMSURWDKGOHVF L PJBXCYZQ'[c=parseInt(1+e.replace(/0?(111|1)/g,d=>+(d>1)),2)]||'473168290 5'[c%11]).join``

console.log(f('101010100010001011101010001011101010001110111011100000001011101110001110111011100010111010001011101010001110101'))
console.log(f('10100000001011100011101110000000101110000000101011101000101000101010001010101'));
console.log(f('1010111011101110001110111011101110111000101110111011101110001110111010101'));
console.log(f('101010001110111011100010101'));

Rick Hitchcock
  • 2.6k
  • 11
  • 17