Skip to content

Instantly share code, notes, and snippets.

@ShimmerFairy
Created August 20, 2010 00:58
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 ShimmerFairy/539337 to your computer and use it in GitHub Desktop.
Save ShimmerFairy/539337 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl6
my $phrase = prompt "Enter what you wish to anagram: ";
say "Removing everything except letters";
$phrase ~~ s:g/<-alpha>//;
die("You didn't enter any letters!") if $phrase.chars == 0;
say "String to be anagrammed: $phrase";
$phrase = $pharse.lc;
say "{[*] 1..$phrase.chars} possibilities (counting the original string)";
my $arraylength = $phrase.chars;
my @anagrams;
while @anagrams.elems < $arraylength {
$_ = $phrase.comb.pick(*);
@anagrams.push($_) if !([+] ($_ «==« @anagrams));
}
say "Results:";
say @anagrams.join(" ");
say "DONE!";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment