As an example, I've written a bit of code here. The result is almost always longer in actual characters, but considerably shorter in syllables. I've restricted the consonants to try to stay with pronouncable monosyllables. Basically, each word is a combination of a consonant cluster from
$consonants1, a vowel from
$vowels, and a final cluster from
$consonants2. You can add anything you want to those, as long as they stay aurally distinct. Or if you find some of them are hard to pronounce or keep distinct, you could remove any that you have trouble saying. As given, it'll convert "4345317546" to "stut-prip-bluv" and back.
#!/usr/bin/perl -l
use strict;
use warnings;
my @consonants1 = qw/ b bl br ch d dr f fr g gr h j k kl kr l m n
p pl pr r s sk skl skr sl sn sp spl spr st
str t tr v vr z /;
my @vowels = qw/ a e i o u /;
my @consonants2 = qw/ b bs d dge ds f g gs ck ll lf m n nd nt p r
s st t v x z /;
my $nwords = 0;
my @num2word;
my %word2num;
for my $c1 (@consonants1){
for my $v (@vowels){
for my $c2 (@consonants2){
$num2word[$nwords] = "$c1$v$c2";
$word2num{"$c1$v$c2"} = $nwords;
$nwords++;
}
}
}
while(<>){
chomp;
if (/^\d+$/){
my @words;
#encode
while ($_ != 0){
push @words, $num2word[$_ % $nwords];
$_ = int ($_ / $nwords);
}
print join "-", @words;
} else {
#decode
my $num = 0;
for my $word (reverse split /-/){
$num *= $nwords;
$num += $word2num{$word};
}
print $num;
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.