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 :)
|
|---|