This post is part of a series on Mohammad Anwar’s excellent Weekly Challenge, where hackers submit solutions in Perl, Raku, or any other language, to two different challenges every week. (It’s a lot of fun, if you’re into that sort of thing.)
This is another one of my suggested tasks, and another time you’re going to read about a personal story that connects me to a task. For many years, right back to very first days I started hacking filesystems and writing kernel code, I’ve often needed to come up with 16- or 32-bit identifiers for things, usually represented in hexadecimal. And to this day, my repertoire of clever identifiers is more or less limited to 0xdeadbeef
and 0xc0dedbad
, and a few others. Let’s change that!
The simple version
A very simple solution simply reads the lines, filters out anything that isn’t the right length, or contains characters that can’t be substituted, and prints out the whole works:
use File::Slurper qw< read_lines >;
my $dict = $ARGV[0] // '../../../data/dictionary.txt';
say for map { y/olist/01157/r }
grep { /^[0-9a-folist]{2,8}$/ } read_lines($dict);
That already gives me some great results, like 0xd15abled
(“disabled”), and is nice and short. However, we didn’t come here for half measures. This version only returns single words, and doesn’t care how many substitutions it has done, so words like 0x57111e57
(“stillest”‽) are fair game.