From 3cf4338ff3149c736057952fbdf7b4817bac72d6 Mon Sep 17 00:00:00 2001 From: Luis Mochan Date: Sat, 19 Nov 2022 20:33:04 -0600 Subject: Small simplification --- challenge-191/wlmb/perl/ch-2d.pl | 12 ++++++------ 1 file 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; -- cgit