Schrift
[thread]1860[/thread]

letter swapping

Leser: 1


<< |< 1 2 >| >> 14 Einträge, 2 Seiten
havi
 2003-09-19 21:18
#18537 #18537
User since
2003-08-04
2036 Artikel
BenutzerIn
[Homepage]
user image
Dieses email hab ich diese Woche ca. 10 mal bekommen...

*HaviGlaubtDasEmailVerfolgtIhmBisInDiePerlCommunity*
Ronnie
 2003-09-19 22:20
#18538 #18538
User since
2003-08-14
2022 Artikel
BenutzerIn
[default_avatar]
@kabel: Finde das aber auch ganz witzig, hatte auch schon überlegt wie man es nachbauen kann. Dein Skript macht das schon ganz gut, irgendwas wird aber bei dem Original noch berücksichtigt evtl. das Silben zusammenbleiben ?!
kabel
 2003-09-20 00:38
#18539 #18539
User since
2003-08-04
704 Artikel
BenutzerIn
[default_avatar]
ok, der original text liest sich wesentlich flüssiger... 8)
-- stefan
Ronnie
 2003-09-20 01:16
#18540 #18540
User since
2003-08-14
2022 Artikel
BenutzerIn
[default_avatar]
Ich mach mit:

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
#!/usr/bin/perl

use strict;
use warnings;

while(<>) {
s/\b(\w+)\b/&wortspiel($1)/ge;
print;
}

sub wortspiel {
if ($_[0] =~ m/\b(\w)(\w+)(.)\b/) {
my @letters = split(//, $2);
shuffle (\@letters);
return $1.join ('', @letters).$3;
}
else {
return $_[0];
}
}

sub shuffle {

# vgl. O'Reilly, Perl-Kochbuch dt., 1. Auflage, 4.17, fisher-yates-shuffle

my $array = shift;
my $i;

for ($i = @$array; --$i; ) {
my $j = int rand ( $i+1 );
next if $i == $j;
@$array[$i, $j] = @$array[$j, $i];
}
}


Gruss,
Ronnie
SirLant
 2003-09-20 16:36
#18541 #18541
User since
2003-08-04
516 Artikel
BenutzerIn
[default_avatar]
Finde das wirklich erstaunlich, habe es zwar inzwischen schon
mehr als in nur einem Forum/Thread,... gelesen, aber es
erstaunt mich immer wieder aufs neue, besonders, dass uns
trotzdem Rechtschreibefehler (meist) sofort auffallen,obwohl
wir das Wort nicht wirklich lesen.
--Programming today is a race between Software Enginers striving to build bigger and better idiot-proof Programs,
and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning!
Ishka
 2003-09-20 19:00
#18542 #18542
User since
2003-08-04
771 Artikel
HausmeisterIn
[Homepage] [default_avatar]
Daimt keigrt man bmtsmet ne bssreere Tetxomkrsesopin hin ;)
sub z{if(@_){1while$x[$k=rand 10];t($t=$x[$k]=1)}print map"$z[$x[$_]]$_".($_%3?
"":"\n"),1..9}sub t{$j=0;$x[$_+1]==$t&&($j+=2**$_)for 0..8;z,die"Gewinner $z[$t]
"if grep$_==($j&$_),7,56,73,84,146,273,292,448;z,die"Gleichstand\n"if@x>9&&!grep
!$_,@x}@x=4;@z=qw{. [ (};z$^T&1;while(<>){next if$_>9||$x[$_];t$t=$x[$_]=2;z 1}
kabel
 2003-09-19 20:49
#18543 #18543
User since
2003-08-04
704 Artikel
BenutzerIn
[default_avatar]
aus einer mail von einem studi-kollegen:
Quote
Aoccdrnig to a rscheearch at an Elingsh uinervtisy, it
deosn't mttaer in waht oredr the ltteers in a wrod
are, the olny iprmoetnt tihng is taht frist and lsat
ltteer is at the rghit pclae. The rset can be a toatl
mses and you can sitll raed it wouthit porbelm. Tihs
is bcuseae we do not raed ervey lteter by it slef but
the wrod as a wlohe. ceehiro.


hier der ziemlich brave perl-code, der das gleiche machen dürfte:
Code: (dl )
1
2
3
4
5
6
use List::Util qw//;
while (<>) {
s {\b(\w)(\w*)(\w)\b}
{$1 . join ("", List::Util::shuffle (split //, $2)) . $3}eg;
print;
}

stelle gerade fest, mit dem text oben funktioniert das sogar erstaunlich gut 8)
-- stefan
kabel
 2003-09-19 21:35
#18544 #18544
User since
2003-08-04
704 Artikel
BenutzerIn
[default_avatar]
use Perl::Poetry;
$kabel->has (capability => forecasting) or print "unfortunately not";
perl: unfortunately not
-- stefan
kabel
 2003-09-20 00:37
#18545 #18545
User since
2003-08-04
704 Artikel
BenutzerIn
[default_avatar]
ich dekne, der txet ist von mnhhancsneed vssrfeat. dmait wrid es - wenn übehraput - sehr swechr, exakt dsiees vrhtaleen zu trfeefn ...

atenohr surcoe of dfieecenrfs mhigt be the use of the egisnlh laugnage. i tihnk, wtreitn egnislh redas lot btteer tahn wttiren gemarn, but - of csoure - i pferer the latetr one.
-- stefan
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
<< |< 1 2 >| >> 14 Einträge, 2 Seiten



View all threads created 2003-09-19 21:18.