Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: A little golfing challenge: Replacing letters with numbers (edited)

by Eily (Monsignor)
on Feb 21, 2019 at 09:46 UTC ( #1230287=note: print w/replies, xml ) Need Help??


in reply to A little golfing challenge: Replacing letters with numbers

The trick with golfing is to wait for Discipulus to have a good idea and steal it from him :P.

perl -nF -E '@h{split"",ARNDBCEQZGHILKMFPSTWYV}=1..22;say"@h{@F}"'
Only works on Linux because it needs double quote context (so you would need two extra chars on windows).

Edit: with the corresponding link

Edit 2: removed the -la options. I don't use -l with say, and -a is implied by -F

Edit 3: shorter than split:

perl -nF -E '@h{ARNDBCEQZGHILKMFPSTWYV=~/./g}=1..22;say"@h{@F}"'

Edit 4: -a is not implied by -F in perl v5.10 though

Replies are listed 'Best First'.
Re^2: A little golfing challenge: Replacing letters with numbers (edited)
by rsFalse (Hermit) on Feb 21, 2019 at 15:54 UTC
    One longer variant, also with extra spaces, but with less than two of them on each line:
    perl -pe 'ARNDBCEQZGHILKMFPSTWYV=~/$_(?{print pos.$"})/ for/./g,$_=$/'
    Corresponding link. (upd. corrected a link)

    And with similar idea but a bit shorter:
    perl -pe 's/./ARNDBCEQZGHILKMFPSTWYV=~m!$&!&&"@+ "/ge'
      perl -pe 's/./ARNDBCEQZGHILKMFPSTWYV=~m!$&!&&"@+ "/ge'

      Really nice! Well done! Going just a little further:

      perl -pe 's/./ARNDBCEQZGHILKMFPSTWYV=~$& &&"@+ "/ge'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1230287]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2020-02-24 14:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (105 votes). Check out past polls.

    Notices?