No such thing as a small change | |
PerlMonks |
Re: A little golfing challenge: replace digits by random letters (updated) -- onelinerby Discipulus (Canon) |
on Feb 10, 2019 at 13:49 UTC ( [id://1229719]=note: print w/replies, xml ) | Need Help?? |
Hello haukex, have you decided to consume all our spare times!?! ;) Not golfed but maybe of interest WebPerl link (requires haukex ;) L* UPDATE see it running perl '-M0;$h{$_}++for 97..122;$"=""' -pe 's/(\d)/(map{chr$_}keys%h)[$1]/eg' input.txt removing unneeded assignemnts.. perl '-M0;$h{$_}++for 97..122' -pe 's/(\d)/(map{chr$_}keys%h)[$1]/eg' input.txt or even.. perl '-M0;@h{97..122}=1x125' -pe 's/(\d)/(map{chr$_}keys%h)[$1]/eg' input.txt perl '-M0;@h{97..122}=1x125'-pe 's/\d/(map{chr$_}keys%h)[$&]/eg' input.txt perl '-M0;@h{97..122}=1x125'-pe 's/\d/chr((keys%h)[$&])/eg' input.txt perl '-M0;undef@h{97..122}'-pe 's/\d/chr((keys%h)[$&])/eg' input.txt perl '-M0;@h{97..122}=1'-pe 's/\d/chr((keys%h)[$&])/eg' input.txt L* congrats Eily for the below reduction! another variation, not highly random.. perl -pe 's/\d/(a..z)[$&-(split"",time)[-1]]/eg' input.txt or.. (shorter than Eily's one ;) perl -pe 's|\d|(a..z)[$&-time%7]|eg' input.txt perl -pe 's|\d|(a..z)[$&-$^T%7]|eg' input.txt L*
There are no rules, there are no thumbs.. Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
In Section
Seekers of Perl Wisdom
|
|