aboutsummaryrefslogtreecommitdiff
path: root/challenge-154/arne-sommer/perl/missing-permutations-perl
blob: b2b1b857425397d718fc6cb3bb9a47090fcfda0f (plain)
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
#! /usr/bin/env perl

use strict;
use warnings;
use feature 'say';
use Algorithm::Combinatorics 'permutations';
use List::Util 'uniq';
use Getopt::Long;

my $verbose      = 0; GetOptions("verbose" => \$verbose);

my $string       = shift(@ARGV) || 'PERL';
my $permutations = shift(@ARGV) || "PELR PREL PERL PRLE PLER PLRE EPRL EPLR ERPL
                                    ERLP ELPR ELRP RPEL RPLE REPL RELP RLPE RLEP
                                    LPER LPRE LEPR LRPE LREP";

my @letters      = split("", $string);
my %permuations  = map { $_ => 1} split(/\s+/, $permutations);

my @missing;

for my $candidate (permutations(\@letters))
{
  my $as_string = join("", @$candidate);
  say ": Checking candidate: $as_string" if $verbose;
  push(@missing, $as_string) unless $permuations{$as_string};
}

say join(", ", uniq @missing) if @missing;