#!/usr/bin/perl
use strict;
use warnings;
my %seen;
for my $file (@ARGV) {
open(my $fh, '<', $file) or die "Unable to open '$file' for reading: $!";
while (<$fh>) {
my ($set) = $_ =~ /^(\w+)/;
powerset($set);
}
}
sub powerset {
my $set = shift @_;
return if $seen{$set}++;
print "$set\n";
powerset($_) for subsets($set);
}
####
sub subsets {
my $set = shift @_;
return if length($set) == 1;
my ($head, $char, $tail) = ($set, '', '');
my @ret;
while ($head) {
$char = chop $head;
push @ret, $head . $tail;
$tail = $char . $tail;
}
return @ret;
}
##
##
sub subsets {
my $set = shift @_;
return if length($set) == 1;
my @list = split //, $set;
my $pos = @list;
my @ret;
while ($pos--) {
push @ret, join '', @list[grep $_ != $pos, 0 .. $#list];
}
return @ret;
}
##
##
# All references to $calls removed
# $limbic_sets = [ ... ]
# foreach my $limbic_set (@$limbic_sets) { ... }
# The above two lines became
open(my $fh, '<', 'phase1.data') or die $!;
while ( <$fh> ) {
my ($limbic_set) = $_ =~ /^(\w+)/;
$limbic_set = [ split //, $limbic_set ];
# ...
}
# removed print "checks set @$limbic_set\n";
# my $format = "%2s" x scalar(@$padded_limbic_set) . " (%d)\n";
# printf($format, (map {defined $_ && $display->{$_} ? $_ : ' '} @$padded_limbic_set), $idx);
# The above 2 lines became
print join '', map {defined $_ && $display->{$_} ? $_ : ''} @$padded_limbic_set;
print "\n";