aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Mochan <mochan@fis.unam.mx>2022-11-19 20:33:04 -0600
committerLuis Mochan <mochan@fis.unam.mx>2022-11-19 20:33:04 -0600
commit3cf4338ff3149c736057952fbdf7b4817bac72d6 (patch)
tree9992b7df99d775b2320910812209650e1432874f
parent09b937cfe3afea655b8f70d9d529a857af8cf0e8 (diff)
downloadperlweeklychallenge-club-3cf4338ff3149c736057952fbdf7b4817bac72d6.tar.gz
perlweeklychallenge-club-3cf4338ff3149c736057952fbdf7b4817bac72d6.tar.bz2
perlweeklychallenge-club-3cf4338ff3149c736057952fbdf7b4817bac72d6.zip
Small simplification
-rwxr-xr-xchallenge-191/wlmb/perl/ch-2d.pl12
1 files changed, 6 insertions, 6 deletions
diff --git a/challenge-191/wlmb/perl/ch-2d.pl b/challenge-191/wlmb/perl/ch-2d.pl
index 260fe94460..440b19dcfc 100755
--- a/challenge-191/wlmb/perl/ch-2d.pl
+++ b/challenge-191/wlmb/perl/ch-2d.pl
@@ -17,29 +17,29 @@ sub cute($n){ # return an iterator to generate all cute sequences of length $n
push @{$sets[$position]}, $_ if ($position+1)%$_==0 || $_%($position+1)==0;
}
}
- sub aux{# closure for an ancilliary iterator constructor
+ my $aux;
+ $aux = # closure for an ancilliary iterator constructor
sub ($pos) { # Returns an iterator for position $pos
#The iterator returns a cute subsecuence and a hash of seen values
# Return a trivial iterator if beyond end
return # trivial iterator beyond position
sub { state $n=0; return $n++? ():([],{})} if $pos >=@sets;
my @set=@{$sets[$pos]};
- my $it=aux($pos+1); # Iterator for next position
+ my $it=$aux->($pos+1); # Iterator for next position
my $candidates=listit(@set); # iterator for candidates
my ($cute, $seen)=$it->(); # initial cute subsequence
sub {
while(1){
while(my $candidate=$candidates->()){
return([$candidate, @$cute], {$candidate, 1, %$seen})
- if !$seen->{$candidate};
+ unless $seen->{$candidate};
}
return () unless ($cute, $seen)=$it->(); # next subsequence or return
$candidates=listit(@set); # reinitalize iterator for candidates
}
}
- }
- }
- aux(0); # return iterator for full sequence
+ };
+ $aux->(0); # return iterator for full sequence
}
die << "EOF" unless @ARGV;