Skip to main content
added 9 characters in body
Source Link
Kjetil S
  • 6.1k
  • 10
  • 22

Perl 5, 283 244 bytes

$s=<>;$s=~s/..{$_}//+print$s=~/(.) \Q$& / for map{vec unpack('u',q{MJZDYEM98;HWE31N4>Y9:6'Y,BZYRSZ1<JI2@]ZH_(Z8H)7@V[G5*V2NC&:NZM3':XVCLCHY2@(IY>WE\5,L<XK*K^6U5+"5K(9*S^)B5CT07:JK_Q:HINCL:J=23LYEL.T,E*".U[)[`HJQ@ZJ/R.F*"6XOJK5B0X`}),$_,2}0..473

Try it online!

This corresponds to:

$L = <<'';                            # length bits in base64
MJZDYEM98;HWE31N4>Y9:6'Y,BZYRSZ1<JI2@]ZH_(Z8H)7@V[G5*V2NC&:NZM3':XVCLCHY2@(IY>WE\5,L<XK*K^6U5+"5K(9*S^)B5CT07:JK_Q:HINCL:J=23LYEL.T,E*".U[)[`HJQ@ZJ/R.F*"6XOJK5B0X`

$s = <>;                              # read inputs
$s =~ s/..{$_}//                      # take current length morse code from start
  + print $s=~/(.) \Q$& /             # ...and print corresponding letter
  for map vec(unpack('u',$L), $_, 2), # find morse code lengths of the letters
      0..473                          # 474 letters

This could perhaps be further shortened by encoding in base128 or directly in "base256". Huffman encoding the lengths could shorten the length data, but most probably enlarge the rest of the code by too much.

Perl 5, 283 244 bytes

$s=<>;$s=~s/..{$_}//+print$s=~/(.) \Q$& / for map{vec unpack('u',q{MJZDYEM98;HWE31N4>Y9:6'Y,BZYRSZ1<JI2@]ZH_(Z8H)7@V[G5*V2NC&:NZM3':XVCLCHY2@(IY>WE\5,L<XK*K^6U5+"5K(9*S^)B5CT07:JK_Q:HINCL:J=23LYEL.T,E*".U[)[`HJQ@ZJ/R.F*"6XOJK5B0X`}),$_,2}0..473

Try it online!

This corresponds to:

$L = <<'';                            # length bits in base64
MJZDYEM98;HWE31N4>Y9:6'Y,BZYRSZ1<JI2@]ZH_(Z8H)7@V[G5*V2NC&:NZM3':XVCLCHY2@(IY>WE\5,L<XK*K^6U5+"5K(9*S^)B5CT07:JK_Q:HINCL:J=23LYEL.T,E*".U[)[`HJQ@ZJ/R.F*"6XOJK5B0X`

$s = <>;                              # read inputs
$s =~ s/..{$_}//                      # take current length morse code from start
  + print $s=~/(.) \Q$& /             # ...and print corresponding letter
  for map vec(unpack('u',$L), $_, 2), # find morse code lengths of the letters
      0..473                          # 474 letters

This could perhaps be further shortened by encoding in base128 or directly in "base256". Huffman encoding the lengths could shorten the length data, but most probably enlarge the rest of the code.

Perl 5, 283 244 bytes

$s=<>;$s=~s/..{$_}//+print$s=~/(.) \Q$& / for map{vec unpack('u',q{MJZDYEM98;HWE31N4>Y9:6'Y,BZYRSZ1<JI2@]ZH_(Z8H)7@V[G5*V2NC&:NZM3':XVCLCHY2@(IY>WE\5,L<XK*K^6U5+"5K(9*S^)B5CT07:JK_Q:HINCL:J=23LYEL.T,E*".U[)[`HJQ@ZJ/R.F*"6XOJK5B0X`}),$_,2}0..473

Try it online!

This corresponds to:

$L = <<'';                            # length bits in base64
MJZDYEM98;HWE31N4>Y9:6'Y,BZYRSZ1<JI2@]ZH_(Z8H)7@V[G5*V2NC&:NZM3':XVCLCHY2@(IY>WE\5,L<XK*K^6U5+"5K(9*S^)B5CT07:JK_Q:HINCL:J=23LYEL.T,E*".U[)[`HJQ@ZJ/R.F*"6XOJK5B0X`

$s = <>;                              # read inputs
$s =~ s/..{$_}//                      # take current length morse code from start
  + print $s=~/(.) \Q$& /             # ...and print corresponding letter
  for map vec(unpack('u',$L), $_, 2), # find morse code lengths of the letters
      0..473                          # 474 letters

This could perhaps be further shortened by encoding in base128 or directly in "base256". Huffman encoding the lengths could shorten the length data, but most probably enlarge the rest of the code by too much.

Rewrote the code. Remembered the `vec` function which is very useful here.
Source Link
Kjetil S
  • 6.1k
  • 10
  • 22

Perl 5, 283 244 bytes

$s=<>;$s=~s/..{$_}//+print$s=~/(.) \Q$& / for map{vec unpack('u',q{MJZDYEM98;HWE31N4>Y9:6'Y,BZYRSZ1<JI2@]ZH_(Z8H)7@V[G5*V2NC&:NZM3':XVCLCHY2@(IY>WE\5,L<XK*K^6U5+"5K(9*S^)B5CT07:JK_Q:HINCL:J=23LYEL.T,E*".U[)[`HJQ@ZJ/R.F*"6XOJK5B0X`}),$_,2}0..473

Try it online!Try it online!

WhichThis corresponds to:

$L = <<''; #length                           # length bits in base64
MJZDYEM98;HWE31N4>Y9:6'Y,BZYRSZ1<JI2@]ZH_(Z8H)7@V[G5*V2NC&:NZM3':XVCLCHY2@(IY>WE\5,L<XK*K^6U5+"5K(9*S^)B5CT07:JK_Q:HINCL:J=23LYEL.T,E*".U[)[`HJQ@ZJ/R.F*"6XOJK5B0X`

$s = <>;  #read                            # read inputs
$s =~ s/..{$_}//                      # take current length morse code from start
  + print $s=~/(.) \Q$& /             # ...and print corresponding letter
  for map vec( unpack('u',$L), $_, 2 ), # find morse code lengths of the letters
      0..473                          # 474 letters

This could perhaps be further shortened by encoding in base128 or directly in "base256". Huffman encoding the lengths could shorten the length data, but most probably unavoidable enlarge the rest of the code.

Perl 5, 283 244 bytes

$s=<>;$s=~s/..{$_}//+print$s=~/(.) \Q$& / for map{vec unpack('u',q{MJZDYEM98;HWE31N4>Y9:6'Y,BZYRSZ1<JI2@]ZH_(Z8H)7@V[G5*V2NC&:NZM3':XVCLCHY2@(IY>WE\5,L<XK*K^6U5+"5K(9*S^)B5CT07:JK_Q:HINCL:J=23LYEL.T,E*".U[)[`HJQ@ZJ/R.F*"6XOJK5B0X`}),$_,2}0..473

Try it online!

Which corresponds to

$L = <<''; #length bits in base64
MJZDYEM98;HWE31N4>Y9:6'Y,BZYRSZ1<JI2@]ZH_(Z8H)7@V[G5*V2NC&:NZM3':XVCLCHY2@(IY>WE\5,L<XK*K^6U5+"5K(9*S^)B5CT07:JK_Q:HINCL:J=23LYEL.T,E*".U[)[`HJQ@ZJ/R.F*"6XOJK5B0X`

$s = <>;  #read inputs
$s =~ s/..{$_}// + print $s=~/(.) \Q$& /
  for map vec( unpack('u',$L), $_, 2 ), 0..473

This could perhaps be further shortened by encoding in base128 or directly in "base256". Huffman encoding the lengths could shorten the length data, but probably unavoidable enlarge the rest of the code.

Perl 5, 283 244 bytes

$s=<>;$s=~s/..{$_}//+print$s=~/(.) \Q$& / for map{vec unpack('u',q{MJZDYEM98;HWE31N4>Y9:6'Y,BZYRSZ1<JI2@]ZH_(Z8H)7@V[G5*V2NC&:NZM3':XVCLCHY2@(IY>WE\5,L<XK*K^6U5+"5K(9*S^)B5CT07:JK_Q:HINCL:J=23LYEL.T,E*".U[)[`HJQ@ZJ/R.F*"6XOJK5B0X`}),$_,2}0..473

Try it online!

This corresponds to:

$L = <<'';                            # length bits in base64
MJZDYEM98;HWE31N4>Y9:6'Y,BZYRSZ1<JI2@]ZH_(Z8H)7@V[G5*V2NC&:NZM3':XVCLCHY2@(IY>WE\5,L<XK*K^6U5+"5K(9*S^)B5CT07:JK_Q:HINCL:J=23LYEL.T,E*".U[)[`HJQ@ZJ/R.F*"6XOJK5B0X`

$s = <>;                              # read inputs
$s =~ s/..{$_}//                      # take current length morse code from start
  + print $s=~/(.) \Q$& /             # ...and print corresponding letter
  for map vec(unpack('u',$L), $_, 2), # find morse code lengths of the letters
      0..473                          # 474 letters

This could perhaps be further shortened by encoding in base128 or directly in "base256". Huffman encoding the lengths could shorten the length data, but most probably enlarge the rest of the code.

Rewrote the code. Remembered the `vec` function which is very useful here.
Source Link
Kjetil S
  • 6.1k
  • 10
  • 22

Perl 5, 283283 244 bytes

$s=<>;@m{split/ $s=<>;$s=~s/,<>}='a'..'z';for$o{$_}//+print$s=~/(map.) ord,split/\Q$& /,unpack'u' for map{vec unpack('u','MZFILEI<EN7);<>06[9q{MJZDYEM98;HWE31N4>Y9:E);TQXKJ-\QHUJA8*WZK\R)HH6"V<NUVA9^C*9.JNM6'Y,9TNI^SBZYRSZ1<JI2@]ZH_(RA8*B+Z8H)7@V[G5*V2NC&:UM_54C-NZM3':XVCLCHY2@(IY>WE\5,L.JJ_Y57A8*4C&3J_F%CL<XK*K^6U5+"5K(9*S^)1U"GJOY/JB5CT07:*YLIJK_Q:HINCL:J=23LYEL.J=8>QLELT,>C(6"[+5CE*".Z"HD["J_,B:*%@NOJI78K``'U[){$s=~s,.[`HJQ@ZJ/R.{$_},,+print$m{$&F*"6XOJK5B0X`}for map{($o>>$_)%4}6,4$_,2,0}0..473

Try it online!Try it online!

Which is the same as this without comments, newlines and spaces:corresponds to

$s=<>;
@m{split/ /,<>}='a'..'z';
for $o (
  map ord,     #convert bytes to ascii numbers
  split//, $L = <<''; #length #splitbits intoin bytesbase64
  unpack'u'MJZDYEM98;HWE31N4>Y9:6'Y,   #base64-decode string on next line
  'MZFILEI<EN7BZYRSZ1<JI2@]ZH_(Z8H);<>06[97@V[G5*V2NC&:E);TQXKJ-\QHUJA8*WZK\R)HH6"V<NUVA9^C*9.JNMNZM3':XVCLCHY2@(IY>WE\5,9TNI^SL<XK*K^6U5+"5K(RA8*B+9*S^)B5CT07:UM_54C-JK_Q:HINCL:J=23LYEL.T,LE*".JJ_Y57A8*4C&3J_F%CU[)1U"GJOY[`HJQ@ZJ/J:*YLI.J=8>QLEL,>C(6"[+5CR.Z"HD["J_,B:*%@NOJI78K``'F*"6XOJK5B0X`
){
$s = <>;  #read inputs
$s =~ $s=~s,s/..{$_},,// + print$m{$&}    #match and print one char + length-1$s=~/(.) from\Q$& input/
    for map {vec($o>>$_)%4} 6,4unpack('u',2$L),0  #convert 0-255 to four$_, 2-bit numbers (or lenghts - 1)
}, 0..473

Input is these two lines on stdin:

  • the long dot-dash-string and
  • the morse code for each letter a-z separated by space

This answer is similar tocould perhaps be further shortened by encoding in base128 or directly in "base256". Huffman encoding the python3 answer from @steviestickman except it uses base64 insteadlengths could shorten the length data, but probably unavoidable enlarge the rest of hexthe code (which is base16 sort of) since base64-decoding is a perl built-in using unpack.

Perl 5, 283 bytes

$s=<>;@m{split/ /,<>}='a'..'z';for$o(map ord,split//,unpack'u','MZFILEI<EN7);<>06[9:E);TQXKJ-\QHUJA8*WZK\R)HH6"V<NUVA9^C*9.JNM,9TNI^S(RA8*B+:UM_54C-,L.JJ_Y57A8*4C&3J_F%C)1U"GJOY/J:*YLI.J=8>QLEL,>C(6"[+5C.Z"HD["J_,B:*%@NOJI78K``'){$s=~s,..{$_},,+print$m{$&}for map{($o>>$_)%4}6,4,2,0}

Try it online!

Which is the same as this without comments, newlines and spaces:

$s=<>;
@m{split/ /,<>}='a'..'z';
for $o (
  map ord,     #convert bytes to ascii numbers
  split//,     #split into bytes
  unpack'u',   #base64-decode string on next line
  'MZFILEI<EN7);<>06[9:E);TQXKJ-\QHUJA8*WZK\R)HH6"V<NUVA9^C*9.JNM,9TNI^S(RA8*B+:UM_54C-,L.JJ_Y57A8*4C&3J_F%C)1U"GJOY/J:*YLI.J=8>QLEL,>C(6"[+5C.Z"HD["J_,B:*%@NOJI78K``'
){
  $s=~s,..{$_},, + print$m{$&}    #match and print one char + length-1 from input
    for map {($o>>$_)%4} 6,4,2,0  #convert 0-255 to four 2-bit numbers (or lenghts - 1)
}

Input is these two lines on stdin:

  • the long dot-dash-string and
  • the morse code for each letter a-z separated by space

This answer is similar to the python3 answer from @steviestickman except it uses base64 instead of hex code (which is base16 sort of) since base64-decoding is a perl built-in using unpack.

Perl 5, 283 244 bytes

$s=<>;$s=~s/..{$_}//+print$s=~/(.) \Q$& / for map{vec unpack('u',q{MJZDYEM98;HWE31N4>Y9:6'Y,BZYRSZ1<JI2@]ZH_(Z8H)7@V[G5*V2NC&:NZM3':XVCLCHY2@(IY>WE\5,L<XK*K^6U5+"5K(9*S^)B5CT07:JK_Q:HINCL:J=23LYEL.T,E*".U[)[`HJQ@ZJ/R.F*"6XOJK5B0X`}),$_,2}0..473

Try it online!

Which corresponds to

$L = <<''; #length bits in base64
MJZDYEM98;HWE31N4>Y9:6'Y,BZYRSZ1<JI2@]ZH_(Z8H)7@V[G5*V2NC&:NZM3':XVCLCHY2@(IY>WE\5,L<XK*K^6U5+"5K(9*S^)B5CT07:JK_Q:HINCL:J=23LYEL.T,E*".U[)[`HJQ@ZJ/R.F*"6XOJK5B0X`

$s = <>;  #read inputs
$s =~ s/..{$_}// + print $s=~/(.) \Q$& /
  for map vec( unpack('u',$L), $_, 2 ), 0..473

This could perhaps be further shortened by encoding in base128 or directly in "base256". Huffman encoding the lengths could shorten the length data, but probably unavoidable enlarge the rest of the code.

added 74 characters in body
Source Link
Kjetil S
  • 6.1k
  • 10
  • 22
Loading
added 122 characters in body
Source Link
Kjetil S
  • 6.1k
  • 10
  • 22
Loading
Source Link
Kjetil S
  • 6.1k
  • 10
  • 22
Loading