Skip to content

Instantly share code, notes, and snippets.

@lestrrat
Created April 28, 2009 08:56
Show Gist options
  • Save lestrrat/103033 to your computer and use it in GitHub Desktop.
Save lestrrat/103033 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/perl
use utf8;
use Encode qw(decode_utf8);
use Data::Dumper;
my $codec = [
[ qw(あ い う え お) ],
[ qw(か き く け こ) ],
[ qw(さ し す せ そ) ],
[ qw(た ち つ て と) ],
[ qw(な に ぬ ね の) ],
[ qw(は ひ ふ へ ほ) ],
[ qw(ま み む め も) ],
[ 'や', undef, 'ゆ', undef, 'よ' ],
[ qw(ら り る れ ろ) ],
[ 'わ', undef, 'を', undef, 'ん' ],
];
my $reverse = {};
my $r = 0;
foreach my $row (@$codec) {
my $c = 0;
foreach my $col (@$row) {
$reverse->{$col} = [ $r, $c++ ];
}
$r++
}
sub to_random_point {
my $point = shift;
if ($point == 0) {
return rand() > 0.5 ? int(rand(10)) . 0 : 0 . int(rand(10));
} elsif ($point == 1) {
return '11';
} elsif ($point == 2) {
return rand() > 0.5 ? '21' : '12';
} elsif ($point == 3) {
return rand() > 0.5 ? '31' : '13';
} elsif ($point == 4) {
return "22";
} elsif ($point == 5) {
return rand() > 0.5 ? '51' : '15';
} elsif ($point == 6) {
return rand() > 0.5 ? '23' : '32';
} elsif ($point == 7) {
return rand() > 0.5 ? '71' : '17';
} elsif ($point == 8) {
my $m = rand();
return $m <= 0.25 ? '81' :
$m > 0.25 && $m <= 0.5 ? '42' :
$m > 0.5 && $m <= 0.75 ? '24' :
'18'
;
} elsif ($point == 9) {
return $m <= 0.33 ? '91' :
$m > 0.33 && $m <= 0.66 ? '33' :
'19'
;
}
}
my @ret;
foreach my $point (decode_utf8($ARGV[0]) =~ /(\p{InHiragana})/g) {
my $codes = $reverse->{$point} or next;
push @ret,
to_random_point($codes->[0]) .
to_random_point($codes->[1])
;
}
print join('/', @ret), "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment