Skip to content

Instantly share code, notes, and snippets.

@zoffixznet

zoffixznet/p6.p6 Secret

Created August 3, 2018 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoffixznet/b569b3f4a337c3c554b22b3fbdc69e90 to your computer and use it in GitHub Desktop.
Save zoffixznet/b569b3f4a337c3c554b22b3fbdc69e90 to your computer and use it in GitHub Desktop.
my %words is Set = lines;
sub make-LDWL(\word, @prev is copy = []) {
make-LDWL $_, take [|@prev, $_] for %words{word.comb.combinations(word.chars-1)».join}:k
}
my @longest;
for sort keys %words {
my $cur := ([$_], |gather make-LDWL $_).sort(-*).head;
say "One of longest chains for `$_` is $cur.join(' ▶ ')";
@longest = $cur if $cur > @longest;
}
say @longest;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment