Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

factor out common prefixes and suffixes if possible.

View prefix_suffix.pm6
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 41 42 43 44 45 46 47
my $in = "rakudo-parrot c8ec1d, rakudo-jvm c8ec1d, rakudo-moar c8ec1d, niecza v24-109-g48a8de3";
my @pieces = $in.split(", ");
 
class Score is rw {
has $.prefix = 0 but "";
has $.postfix = 0 but "";
has @.subpieces;
has @.rest;
has $.output;
}
 
my %scoring{Any};
 
for @pieces.keys.combinations(1..*) {
my @subpieces = @pieces[@$_];
my Score $score .= new(:@subpieces);
for 1..([max] @subpieces>>.chars) {
last unless [eq] @subpieces>>.substr(0, $_);
$score.prefix = $_ but @subpieces[0].substr(0, $_);
}
for 1..(([max] @subpieces>>.chars) - $score.prefix) {
last unless [eq] @subpieces>>.substr(* - $_);
$score.postfix = $_ but @subpieces[0].substr(* - $_);
}
$score.rest = @subpieces>>.substr($score.prefix, * - $score.postfix);
$score.output = ~$score.prefix ~ '{' ~ $score.rest.join(", ") ~ '}' ~ ~$score.postfix;
%scoring{@subpieces.item} = $score;
}
 
.value.output.say for %scoring;
 
# now that we have simple bits, we can construct bigger pieces out of them
# and just use the shortest for each combination
 
for %scoring.kv -> $pieces, $score {
# @pieces is our target combination of bits.
# we'll look for ways to shorten the output we've got by replacing
# sub-sections with other smaller thingies.
say "we're trying to improve our $pieces score";
say %scoring.keys.perl;
for %scoring.keys.combinations(1..*) {
# first, check if we'll reach 100% coverage of our $pieces
say "we're now trying to get to: $pieces";
say $_;
say;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.