Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Using the olde times internet

by oiskuu (Hermit)
on Feb 16, 2016 at 14:28 UTC ( #1155358=note: print w/replies, xml ) Need Help??

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{"temnaiogkdwrusXqzycxbjplfvh"=~/./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{"etianmsurwdkgohvflpjbxcyzq"=~/./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"etianmsurwdkgohvflpjbxcyzq",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


    • 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

    oiskuus last variant is 87 bytes long:

    s!.!sprintf("%b ",2+index"etianmsurwdkgohvflpjbxcyzq",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"etianmsurwdkgohvflpjbxcyzq",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, heres a 87 bytes variant that doesnt require the -p flag. Its longer by StackExchanges standard (where -p counts as a single additional byte), but shorter for, 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 theres still room for improvement.

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1155358]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2017-12-12 23:33 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (341 votes). Check out past polls.