Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: A little golfing challenge: Replacing letters with numbers

by vr (Curate)
on Feb 22, 2019 at 11:13 UTC ( #1230369=note: print w/replies, xml ) Need Help??

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

Here's my answer, FWIW, but it's not to the question in topic :). I was playing with idea of packing encoding information as tightly as possible, bit vectors, as "5 bits of code per letter", this avenue to explore. Of course, in the end it turned out to be longest among all solutions here, so no need to post it.

But, what if letters are coded as random numbers e.g. up to 1000? With 26 random 3-digit numbers (code to generate this encoding is obvious, not shown), and based on Eily's answer, solution could be:

$_ = 'NDDDDTSVCLGTRQCSWFAGCTNRTWNSSA 0'; my @F = split ''; @h{A..Z}=('27941492412912434962583369414978036693514585011981639390315 +1901525290851349853' =~/.../g);say"@h{@F}";

Now, my idea (here with 10 bits per code) is becoming competitive, length-wise:

@h{A..Z}=map 1023& Math::BigInt->from_base(D3PghSS0AZyLfhkL67kHFiuXWoB +6p9GUkgznoeEO1eNj, 62)>>10*$_,0..25;say"@h{@F}";

It's still slightly longer, and I need to use the module. I think, if number of symbols grows (e.g., 52 letters and 10 digits i.e. 62), then this solution will scale better and better :)

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2020-11-29 23:32 GMT
Find Nodes?
    Voting Booth?

    No recent polls found