Thread letter swapping (13 answers)
Opened by havi at 2003-09-19 21:18

kabel
 2003-09-20 00:59
#18546 #18546
User since
2003-08-04
704 Artikel
BenutzerIn
[default_avatar]
das ist mein momentanes skript. vielleicht will ja jemand mitmachen? 8)

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use List::Util qw//;
use constant DEBUG => 1;
my %hash = ();
while (<>) {
s {\b(\w)(\w+)(\w)\b}
{heuristic_replace (eval join (", " => map {"\$$_"} 1 .. 3))}eg;
print;
if (DEBUG) { push @{ $hash{length $_} }, $_ foreach split; }
}

if (DEBUG) {
print "\nWORD LIST\n";
foreach my $l (sort grep {$_ > 3} keys %hash) {
print "length $l:\n";
print "\t$_\n" foreach @{ $hash{$l} };
print "\n";
}
}

sub heuristic_replace {
my ($first, $word, $last) = @_;

print "\nDEBUG: [$first] [$word] [$last]\n" if DEBUG;

my $word_len = length ($word);
my $first_is_consonant = (grep {$first eq $_} split //, "aeiou")>0?1:0;
my $last_is_consonant = (grep {$last eq $_} split //, "aeiou")>0?1:0;

print "first_is_consonant: $first_is_consonant\n" if DEBUG;
print "last_is_consonant: $last_is_consonant\n" if DEBUG;

# words of length = 3 are left untouched
return join "", @_ if $word_len == 1;

# words of length = 4 have their middle two chars swapped
$word_len == 2 and return $first . reverse ($word) . $last;

# do a generic shuffle at the moment
return $first . join ("", List::Util::shuffle (split //, $word)) . $last;
}
-- stefan

View full thread letter swapping