Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,29 @@
use strict;
use warnings;
use feature 'bitwise';
use List::Util qw(shuffle);
use Algorithm::Permute;
best_shuffle($_) for qw(abracadabra seesaw elk grrrrrr up a);
sub best_shuffle {
my ($original_word) = @_;
my $best_word = $original_word;
my $best_score = length $best_word;
my @shuffled = shuffle split //, $original_word;
my $iterator = Algorithm::Permute->new(\@shuffled);
while( my @array = $iterator->next ) {
my $word = join '', @array;
# For each letter which is the same in the two words,
# there will be a \x00 in the "^" of the two words.
# The tr operator is then used to count the "\x00"s.
my $score = ($original_word ^. $word) =~ tr/\x00//;
next if $score >= $best_score;
($best_word, $best_score) = ($word, $score);
last if $score == 0;
}
print "$original_word, $best_word, $best_score\n";
}

View file

@ -0,0 +1,28 @@
use strict;
use warnings;
use feature 'bitwise';
use List::Util qw(shuffle);
best_shuffle($_) for qw(abracadabra seesaw elk grrrrrr up a);
sub best_shuffle {
my ($original_word) = @_;
my @s = split //, $original_word;
my @t = shuffle @s;
for my $i ( 0 .. $#s ) {
for my $j ( 0 .. $#s ) {
next if $j == $i or
$t[$i] eq $s[$j] or
$t[$j] eq $s[$i];
@t[$i,$j] = @t[$j,$i];
last;
}
}
my $word = join '', @t;
my $score = ($original_word ^. $word) =~ tr/\x00//;
print "$original_word, $word, $score\n";
}