http://www.perlmonks.org?node_id=1155358


in reply to Using the olde times internet

Here's my alternative take. It's in the form of a filter (reads from standard input).

#! /usr/bin/perl -p @T{"temnaiogkdwrusXöqzycxbjpälüfvh"=~/./g}=grep!/[^12]/,1..2x4; s/./$T{lc$&} /g;y/12/-./

Update. A transformed (y/12/21/) mapping moves the X to the string end where it can be dropped; one char saved.

#! /usr/bin/perl -p @T{"etianmsurwdkgohvfüläpjbxcyzqö"=~/./g}=grep!/[^12]/,1..2x4; s/./$T{lc$&} /g;y/12/.-/

Update3. Super Search found me this: Morse Code as binary. (And this, this). Here's another variant.

#! /usr/bin/perl -p s!.!sprintf("%b ",2+index"etianmsurwdkgohvfüläpjbxcyzqö",lc$&)=~s/.//r +=~y/01/.-/r!ge

As for golfing tricks and links, take a look at the eyepopslikeamosquito user page. There there's a full section of golfing articles.

Replies are listed 'Best First'.
Re^2: Using the olde times internet
by lemonCurd (Novice) on Feb 18, 2016 at 16:19 UTC

    I'm

    • impressed (I'm still trying to get all the tricks, but hey, I've work to do from time to time)
    • a little bit depressed (I thought the idea of arranging the characters in Morse specific order was, well, unique),
    • feeling a little bit cheated on (-p really feels like a cheap trick, doesn't it?)
    And I'm learning tons of stuff. Thanks, guys!

Re^2: Using the olde times internet
by Anonymous Monk on Mar 08, 2016 at 15:42 UTC

    oiskuu’s last variant is 87 bytes long:

    s!.!sprintf("%b ",2+index"etianmsurwdkgohvfüläpjbxcyzqö",lc$&)=~s/.//r=~y/01/.-/r!ge

    By assigning to $_, we can scrap the parentheses and the two =~, saving two bytes:

    s!.!$_=sprintf"%b ",2+index"etianmsurwdkgohvfüläpjbxcyzqö",lc$&;s/.//;y/01/.-/r!ge

    Dropping the support for diacritics (only ü, ä and ö where supported anyway) easily saves another five bytes:

    s!.!$_=sprintf"%b ",2+index etianmsurwdkgohvfXlXpjbxcyzq,lc$&;s/.//;y/01/.-/r!ge

    With some shuffling around, we can shave off another byte: (note that this version prints a leading whitespace, while the previous ones printed a trailing whitespace)

    s!.!sprintf" %b",2+index etianmsurwdkgohvfXlXpjbxcyzq,lc$&!ge;s/ ./ /g;y/01/.-/

    Using a regex instead of index saves yet another byte, now down to 78:

    s!.!XetianmsurwdkgohvfXlXpjbxcyzq=~lc$&;sprintf" %b","@+"!ge;s/ ./ /g;y/01/.-/

    Finally, here’s a 87 bytes variant that doesn’t require the -p flag. It’s longer by StackExchange’s standard (where -p counts as a single additional byte), but shorter for codegolf.com, where you would have to write the entire 10-byte shebang line.

    print+sprintf("%b ","@+")=~s/.//r=~y/01/.-/rwhile-etianmsurwdkgohvfXlXpjbxcyzq=~lc getc

    I think there’s still room for improvement.

      I accidentally posted the above as an Anonymous Monk, and now I can’t edit it to fix the glaring typo :/